Search in sources :

Example 56 with EnvVars

use of hudson.EnvVars in project support-core-plugin by jenkinsci.

the class AgentsConfigFileTest method agentsConfigFile.

@Test
public void agentsConfigFile() throws Exception {
    j.createSlave("node1", "node1", new EnvVars());
    AgentsConfigFile comp = new AgentsConfigFile();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    comp.addContents(new Container() {

        @Override
        public void add(@CheckForNull Content content) {
            try {
                content.writeTo(baos);
            } catch (IOException e) {
                fail(e.getMessage());
            }
        }
    });
    String fileContent = baos.toString();
    assertTrue(fileContent.contains("<name>node1</name>"));
}
Also used : Container(com.cloudbees.jenkins.support.api.Container) EnvVars(hudson.EnvVars) Content(com.cloudbees.jenkins.support.api.Content) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 57 with EnvVars

use of hudson.EnvVars in project sonar-scanner-jenkins by SonarSource.

the class TriggersConfigTest method build_parameters.

/**
 * See SONARPLUGINS-1338
 */
@Test
public void build_parameters() throws IOException, InterruptedException {
    AbstractBuild<?, ?> build = mockBuildWithCauses(new TriggersConfig.SonarCause());
    EnvVars env_vars = new EnvVars();
    when(build.getEnvironment(listener)).thenReturn(env_vars);
    Map<String, String> build_vars = new HashMap<String, String>();
    when(build.getBuildVariables()).thenReturn(build_vars);
    assertThat(triggers.isSkipSonar(build, listener)).isNull();
    triggers.setEnvVar("SKIP_SONAR");
    assertThat(triggers.isSkipSonar(build, listener)).isNull();
    build_vars.put("SKIP_SONAR", "true");
    assertThat(triggers.isSkipSonar(build, listener)).isNotNull();
}
Also used : EnvVars(hudson.EnvVars) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 58 with EnvVars

use of hudson.EnvVars in project sonar-scanner-jenkins by SonarSource.

the class TriggersConfigTest method env_var.

/**
 * See SONARPLUGINS-1886
 */
@Test
public void env_var() throws IOException, InterruptedException {
    AbstractBuild<?, ?> build = mockBuildWithCauses(new TriggersConfig.SonarCause());
    EnvVars env_vars = new EnvVars();
    when(build.getEnvironment(listener)).thenReturn(env_vars);
    Map<String, String> build_vars = new HashMap<String, String>();
    when(build.getBuildVariables()).thenReturn(build_vars);
    assertThat(triggers.isSkipSonar(build, listener)).isNull();
    triggers.setEnvVar("SKIP_SONAR");
    assertThat(triggers.isSkipSonar(build, listener)).isNull();
    env_vars.put("SKIP_SONAR", "true");
    assertThat(triggers.isSkipSonar(build, listener)).isNotNull();
}
Also used : EnvVars(hudson.EnvVars) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 59 with EnvVars

use of hudson.EnvVars in project evosuite by EvoSuite.

the class ProjectAction method perform.

public void perform(AbstractMavenProject<?, ?> project, AbstractBuild<?, ?> build, BuildListener listener) throws InterruptedException, IOException {
    EnvVars env = build.getEnvironment(listener);
    env.overrideAll(build.getBuildVariables());
    VirtualChannel channel = build.getWorkspace().getChannel();
    MavenModuleSet prj = (MavenModuleSet) this.project;
    for (MavenModule module : prj.getModules()) {
        FilePath fp = new FilePath(channel, build.getWorkspace().getRemote() + File.separator + (module.getRelativePath().isEmpty() ? "" : module.getRelativePath() + File.separator) + Properties.CTG_DIR + File.separator + Properties.CTG_PROJECT_INFO);
        if (!fp.exists()) {
            listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "There is not any " + fp.getRemote() + " file for module " + module.getName());
            continue;
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        fp.copyTo(out);
        ByteArrayInputStream projectXML = new ByteArrayInputStream(out.toByteArray());
        listener.getLogger().println(EvoSuiteRecorder.LOG_PREFIX + "Analysing " + Properties.CTG_PROJECT_INFO + " file from " + fp.getRemote());
        ModuleAction m = new ModuleAction(build, module.getName());
        if (!m.build(channel, projectXML, listener)) {
            continue;
        }
        this.modules.add(m);
    }
}
Also used : FilePath(hudson.FilePath) EnvVars(hudson.EnvVars) VirtualChannel(hudson.remoting.VirtualChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) MavenModule(hudson.maven.MavenModule) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MavenModuleSet(hudson.maven.MavenModuleSet)

Example 60 with EnvVars

use of hudson.EnvVars in project sonar-scanner-jenkins by SonarSource.

the class MsBuildSQRunnerBegin method perform.

@Override
public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException {
    ArgumentListBuilder args = new ArgumentListBuilder();
    EnvVars env = BuilderUtils.getEnvAndBuildVars(run, listener);
    SonarInstallation sonarInstallation = getSonarInstallation(getSonarInstallationName(), listener);
    MsBuildSQRunnerInstallation msBuildScanner = getDescriptor().getMsBuildScannerInstallation(msBuildScannerInstallationName);
    run.addAction(new SonarQubeScannerMsBuildParams(msBuildScannerInstallationName, getSonarInstallationName()));
    args.add(getExeName(msBuildScanner, env, launcher, listener, workspace));
    Map<String, String> props = getSonarProps(sonarInstallation);
    addArgsTo(args, sonarInstallation, env, props);
    int result = launcher.launch().cmds(args).envs(env).stdout(listener).pwd(BuilderUtils.getModuleRoot(run, workspace)).join();
    if (result != 0) {
        throw new AbortException(Messages.MSBuildScanner_ExecFailed(result));
    }
}
Also used : EnvVars(hudson.EnvVars) ArgumentListBuilder(hudson.util.ArgumentListBuilder) AbortException(hudson.AbortException)

Aggregations

EnvVars (hudson.EnvVars)72 Test (org.junit.Test)25 IOException (java.io.IOException)17 FilePath (hudson.FilePath)11 TaskListener (hudson.model.TaskListener)9 AbortException (hudson.AbortException)8 ClientConfiguration (com.amazonaws.ClientConfiguration)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Computer (hudson.model.Computer)5 FreeStyleProject (hudson.model.FreeStyleProject)5 ArgumentListBuilder (hudson.util.ArgumentListBuilder)5 ParameterValue (hudson.model.ParameterValue)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Step (org.jenkinsci.plugins.workflow.steps.Step)4 ConduitAPIClient (com.uber.jenkins.phabricator.conduit.ConduitAPIClient)3 ConduitAPIException (com.uber.jenkins.phabricator.conduit.ConduitAPIException)3 Differential (com.uber.jenkins.phabricator.conduit.Differential)3 DifferentialClient (com.uber.jenkins.phabricator.conduit.DifferentialClient)3