use of hudson.EnvVars in project hudson-2.x by hudson.
the class CommandInterpreter method perform.
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, TaskListener listener) throws InterruptedException {
FilePath ws = build.getWorkspace();
FilePath script = null;
try {
try {
script = createScriptFile(ws);
} catch (IOException e) {
Util.displayIOException(e, listener);
e.printStackTrace(listener.fatalError(Messages.CommandInterpreter_UnableToProduceScript()));
return false;
}
int r;
try {
EnvVars envVars = build.getEnvironment(listener);
// convert variables to all upper cases.
for (Map.Entry<String, String> e : build.getBuildVariables().entrySet()) envVars.put(e.getKey(), e.getValue());
r = launcher.launch().cmds(buildCommandLine(script)).envs(envVars).stdout(listener).pwd(ws).join();
} catch (IOException e) {
Util.displayIOException(e, listener);
e.printStackTrace(listener.fatalError(Messages.CommandInterpreter_CommandFailed()));
r = -1;
}
return r == 0;
} finally {
try {
if (script != null)
script.delete();
} catch (IOException e) {
Util.displayIOException(e, listener);
e.printStackTrace(listener.fatalError(Messages.CommandInterpreter_UnableToDelete(script)));
}
}
}
use of hudson.EnvVars in project hudson-2.x by hudson.
the class AbstractBuild method getEnvironment.
@Override
public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedException {
EnvVars env = super.getEnvironment(log);
FilePath ws = getWorkspace();
if (// if this is done very early on in the build, workspace may not be decided yet. see HUDSON-3997
ws != null)
env.put("WORKSPACE", ws.getRemote());
// servlet container may have set CLASSPATH in its launch script,
// so don't let that inherit to the new child process.
// see http://www.nabble.com/Run-Job-with-JDK-1.4.2-tf4468601.html
env.put("CLASSPATH", "");
JDK jdk = project.getJDK();
if (jdk != null) {
Computer computer = Computer.currentComputer();
if (computer != null) {
// just in case were not in a build
jdk = jdk.forNode(computer.getNode(), log);
}
jdk.buildEnvVars(env);
}
project.getScm().buildEnvVars(this, env);
if (buildEnvironments != null)
for (Environment e : buildEnvironments) e.buildEnvVars(env);
for (EnvironmentContributingAction a : Util.filter(getActions(), EnvironmentContributingAction.class)) a.buildEnvVars(this, env);
EnvVars.resolve(env);
return env;
}
use of hudson.EnvVars in project blueocean-plugin by jenkinsci.
the class GitBareRepoReadSaveRequest method cloneRepo.
GitClient cloneRepo() throws InterruptedException, IOException {
EnvVars environment = new EnvVars();
TaskListener taskListener = new LogTaskListener(Logger.getAnonymousLogger(), Level.ALL);
String gitExe = gitTool.getGitExe();
GitClient git = org.jenkinsci.plugins.gitclient.Git.with(taskListener, environment).in(repositoryPath).using(gitExe).getClient();
git.addCredentials(gitSource.getRemote(), getCredential());
try {
git.clone(gitSource.getRemote(), "origin", true, null);
log.fine("Repository " + gitSource.getRemote() + " cloned to: " + repositoryPath.getCanonicalPath());
} catch (GitException e) {
// check if this is an empty repository
boolean isEmptyRepo = false;
try {
if (git.getRemoteReferences(gitSource.getRemote(), null, true, false).isEmpty()) {
isEmptyRepo = true;
}
} catch (GitException ge) {
// *sigh* @ this necessary hack; {@link org.jenkinsci.plugins.gitclient.CliGitAPIImpl#getRemoteReferences}
if ("unexpected ls-remote output ".equals(ge.getMessage())) {
// blank line, command succeeded
isEmptyRepo = true;
}
// ignore other reasons
}
if (isEmptyRepo) {
git.init();
git.addRemoteUrl("origin", gitSource.getRemote());
log.fine("Repository " + gitSource.getRemote() + " not found, created new to: " + repositoryPath.getCanonicalPath());
} else {
throw e;
}
}
return git;
}
use of hudson.EnvVars in project sonar-scanner-jenkins by SonarSource.
the class SonarRunnerBuilderTest method prepareMockWorkspace.
@Before
public void prepareMockWorkspace() throws IOException {
workspace = temp.newFolder();
moduleDir = new File(workspace, "trunk");
FileUtils.forceMkdir(moduleDir);
args = new ArgumentListBuilder();
argsBuilder = new ExtendedArgumentListBuilder(args, false);
AbstractProject<?, ?> p = mock(AbstractProject.class);
SCM scm = mock(SCM.class);
FilePath workspacePath = new FilePath(workspace);
when(scm.getModuleRoot(eq(workspacePath), any(AbstractBuild.class))).thenReturn(new FilePath(moduleDir));
when(p.getScm()).thenReturn(scm);
build = new MyBuild(p);
build.setWorkspace(workspacePath);
listener = mock(BuildListener.class);
env = new EnvVars();
}
use of hudson.EnvVars in project sonar-scanner-jenkins by SonarSource.
the class MsBuildSQRunnerBeginTest method addEnvVar.
private void addEnvVar(String key, String value) {
EnvironmentVariablesNodeProperty prop = new EnvironmentVariablesNodeProperty();
EnvVars envVars = prop.getEnvVars();
envVars.put(key, value);
j.jenkins.getGlobalNodeProperties().add(prop);
}
Aggregations