Search in sources :

Example 26 with EnvVars

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)));
        }
    }
}
Also used : FilePath(hudson.FilePath) EnvVars(hudson.EnvVars) IOException(java.io.IOException) Map(java.util.Map)

Example 27 with EnvVars

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;
}
Also used : FilePath(hudson.FilePath) EnvVars(hudson.EnvVars)

Example 28 with EnvVars

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;
}
Also used : EnvVars(hudson.EnvVars) GitException(hudson.plugins.git.GitException) LogTaskListener(hudson.util.LogTaskListener) TaskListener(hudson.model.TaskListener) LogTaskListener(hudson.util.LogTaskListener) GitClient(org.jenkinsci.plugins.gitclient.GitClient)

Example 29 with EnvVars

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();
}
Also used : FilePath(hudson.FilePath) BuildListener(hudson.model.BuildListener) EnvVars(hudson.EnvVars) AbstractBuild(hudson.model.AbstractBuild) ExtendedArgumentListBuilder(hudson.plugins.sonar.utils.ExtendedArgumentListBuilder) ArgumentListBuilder(hudson.util.ArgumentListBuilder) ExtendedArgumentListBuilder(hudson.plugins.sonar.utils.ExtendedArgumentListBuilder) SCM(hudson.scm.SCM) File(java.io.File) Before(org.junit.Before)

Example 30 with 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);
}
Also used : EnvVars(hudson.EnvVars) EnvironmentVariablesNodeProperty(hudson.slaves.EnvironmentVariablesNodeProperty)

Aggregations

EnvVars (hudson.EnvVars)64 Test (org.junit.Test)23 IOException (java.io.IOException)15 FilePath (hudson.FilePath)11 ClientConfiguration (com.amazonaws.ClientConfiguration)7 ArgumentListBuilder (hudson.util.ArgumentListBuilder)7 TaskListener (hudson.model.TaskListener)6 AbortException (hudson.AbortException)5 HashMap (java.util.HashMap)5 MavenModuleSet (hudson.maven.MavenModuleSet)4 FreeStyleProject (hudson.model.FreeStyleProject)4 ParameterValue (hudson.model.ParameterValue)4 Launcher (hudson.Launcher)3 GitException (hudson.plugins.git.GitException)3 LogTaskListener (hudson.util.LogTaskListener)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 NodeJSInstallation (jenkins.plugins.nodejs.tools.NodeJSInstallation)3 ConduitAPIClient (com.uber.jenkins.phabricator.conduit.ConduitAPIClient)2 ConduitAPIException (com.uber.jenkins.phabricator.conduit.ConduitAPIException)2