Search in sources :

Example 31 with EnvVars

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

the class SonarBuildWrapperTest method testEnvironmentMojoVersion.

@Test
public void testEnvironmentMojoVersion() {
    installation = new SonarInstallation(null, null, null, "2.0", null, null, null);
    Map<String, String> map = SonarBuildWrapper.createVars(installation, new EnvVars());
    assertThat(map).containsEntry("SONAR_MAVEN_GOAL", "org.codehaus.mojo:sonar-maven-plugin:2.0:sonar");
}
Also used : EnvVars(hudson.EnvVars) Test(org.junit.Test)

Example 32 with EnvVars

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

the class SonarBuildWrapperTest method testEnvironment.

@Test
public void testEnvironment() {
    installation = createTestInstallationForEnv();
    EnvVars initialEnvironment = new EnvVars();
    initialEnvironment.put("MY_SERVER", "myserver");
    initialEnvironment.put("MY_PORT", "10000");
    initialEnvironment.put("MY_VALUE", "myValue");
    Map<String, String> map = SonarBuildWrapper.createVars(installation, initialEnvironment);
    assertThat(map).containsEntry("SONAR_HOST_URL", "http://myserver:10000");
    assertThat(map).containsEntry("SONAR_CONFIG_NAME", "local");
    // variable in the value should be resolved
    assertThat(map).containsEntry("SONAR_AUTH_TOKEN", MYTOKEN);
    assertThat(map).containsEntry("SONAR_MAVEN_GOAL", "sonar:sonar");
    assertThat(map).containsEntry("SONAR_EXTRA_PROPS", "-Dkey=myValue -X");
    assertThat(map).containsEntry("SONARQUBE_SCANNER_PARAMS", "{ \"sonar.host.url\" : \"http:\\/\\/myserver:10000\", \"sonar.login\" : \"" + MYTOKEN + "\", \"key\" : \"myValue\"}");
}
Also used : EnvVars(hudson.EnvVars) Test(org.junit.Test)

Example 33 with EnvVars

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

the class SonarPublisher method getPomName.

private String getPomName(AbstractBuild<?, ?> build, BuildListener listener) throws IOException, InterruptedException {
    String pomName;
    MavenModuleSet mavenModuleProject = getMavenProject(build);
    if (mavenModuleProject != null) {
        EnvVars envVars = build.getEnvironment(listener);
        pomName = mavenModuleProject.getRootPOM(envVars);
    } else {
        pomName = getRootPom();
    }
    if (StringUtils.isEmpty(pomName)) {
        pomName = "pom.xml";
    }
    return pomName;
}
Also used : EnvVars(hudson.EnvVars) MavenModuleSet(hudson.maven.MavenModuleSet)

Example 34 with EnvVars

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

the class SonarRunnerBuilder method perform.

private void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException {
    if (!SonarInstallation.isValid(getInstallationName(), listener)) {
        throw new AbortException("Invalid SonarQube server installation");
    }
    ArgumentListBuilder args = new ArgumentListBuilder();
    EnvVars env = BuilderUtils.getEnvAndBuildVars(run, listener);
    SonarRunnerInstallation sri = getSonarRunnerInstallation();
    if (sri == null) {
        // No idea if the path contains old sonar-runner or new sonar-scanner, so prefer the new one
        args.add(launcher.isUnix() ? "sonar-scanner" : "sonar-scanner.bat");
    } else {
        sri = BuilderUtils.getBuildTool(sri, env, listener, workspace);
        String exe = sri.getExecutable(launcher);
        if (exe == null) {
            Logger.printFailureMessage(listener);
            String msg = Messages.SonarScanner_ExecutableNotFound(sri.getName());
            listener.fatalError(msg);
            throw new AbortException(msg);
        }
        args.add(exe);
    }
    SonarInstallation sonarInst = getSonarInstallation();
    addTaskArgument(args);
    addAdditionalArguments(args, sonarInst);
    ExtendedArgumentListBuilder argsBuilder = new ExtendedArgumentListBuilder(args, launcher.isUnix());
    populateConfiguration(argsBuilder, run, workspace, listener, env, sonarInst);
    // Java
    computeJdkToUse(run, workspace, listener, env);
    // Java options
    env.put("SONAR_SCANNER_OPTS", getJavaOpts());
    // For backward compatibility with old sonar-runner
    env.put("SONAR_RUNNER_OPTS", getJavaOpts());
    long startTime = System.currentTimeMillis();
    int exitCode;
    try {
        exitCode = executeSonarQubeScanner(run, workspace, launcher, listener, args, env);
    } catch (IOException e) {
        handleErrors(listener, sri, startTime, e);
        exitCode = -1;
    }
    // with workflows, we don't have realtime access to build logs, so url might be null
    // if the analyis doesn't succeed, it will also be null
    SonarUtils.addBuildInfoTo(run, listener, workspace, getSonarInstallation().getName());
    if (exitCode != 0) {
        throw new AbortException("SonarQube scanner exited with non-zero code: " + exitCode);
    }
}
Also used : EnvVars(hudson.EnvVars) ExtendedArgumentListBuilder(hudson.plugins.sonar.utils.ExtendedArgumentListBuilder) ArgumentListBuilder(hudson.util.ArgumentListBuilder) ExtendedArgumentListBuilder(hudson.plugins.sonar.utils.ExtendedArgumentListBuilder) IOException(java.io.IOException) AbortException(hudson.AbortException)

Example 35 with EnvVars

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

the class BuilderUtilsTest method buildEnv.

@Test
public void buildEnv() throws IOException, InterruptedException {
    TaskListener l = mock(TaskListener.class);
    AbstractBuild<?, ?> r = mock(AbstractBuild.class);
    EnvVars env = new EnvVars("key", "value", "key2", "value2");
    when(r.getEnvironment(l)).thenReturn(env);
    when(r.getBuildVariables()).thenReturn(ImmutableMap.of("key", "newValue"));
    env = BuilderUtils.getEnvAndBuildVars(r, l);
    assertThat(env.descendingMap()).contains(entry("key", "newValue"), entry("key2", "value2"));
}
Also used : EnvVars(hudson.EnvVars) TaskListener(hudson.model.TaskListener) Test(org.junit.Test)

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