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");
}
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\"}");
}
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;
}
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);
}
}
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"));
}
Aggregations