use of hudson.EnvVars in project sonar-scanner-jenkins by SonarSource.
the class MsBuildSQRunnerEnd 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);
SonarQubeScannerMsBuildParams beginParams = run.getAction(SonarQubeScannerMsBuildParams.class);
if (beginParams == null) {
throw new AbortException(Messages.MsBuildScannerEnd_NoBeginStep());
}
String scannerName = beginParams.getScannerName();
String sonarInstName = beginParams.getSqServerName();
SonarInstallation sonarInstallation = getSonarInstallation(sonarInstName, listener);
MsBuildSQRunnerInstallation msBuildScanner = Jenkins.getInstance().getDescriptorByType(MsBuildSQRunnerBegin.DescriptorImpl.class).getMsBuildScannerInstallation(scannerName);
args.add(getExeName(msBuildScanner, env, launcher, listener, workspace));
addArgs(args, env, sonarInstallation);
int result = launcher.launch().cmds(args).envs(env).stdout(listener).pwd(BuilderUtils.getModuleRoot(run, workspace)).join();
if (result != 0) {
addBadge(run, listener, workspace, sonarInstallation);
throw new AbortException(Messages.MSBuildScanner_ExecFailed(result));
}
addBadge(run, listener, workspace, sonarInstallation);
}
use of hudson.EnvVars in project sonar-scanner-jenkins by SonarSource.
the class SonarMaven method executeMaven.
public static boolean executeMaven(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, String mavenName, String pom, SonarInstallation sonarInstallation, SonarPublisher sonarPublisher, JDK jdk, SettingsProvider settings, GlobalSettingsProvider globalSettings, boolean usesLocalRepository) throws IOException, InterruptedException {
MavenModuleSet mavenModuleProject = sonarPublisher.getMavenProject(build);
EnvVars envVars = build.getEnvironment(listener);
/**
* MAVEN_OPTS
*/
String mvnOptions = sonarPublisher.getMavenOpts();
if (StringUtils.isEmpty(mvnOptions) && mavenModuleProject != null && StringUtils.isNotEmpty(mavenModuleProject.getMavenOpts())) {
mvnOptions = mavenModuleProject.getMavenOpts();
}
// Private Repository and Alternate Settings
LocalRepositoryLocator locaRepositoryToUse = usesLocalRepository ? new PerJobLocalRepositoryLocator() : new DefaultLocalRepositoryLocator();
SettingsProvider settingsToUse = settings;
GlobalSettingsProvider globalSettingsToUse = globalSettings;
if (mavenModuleProject != null) {
// If we are on a Maven job then take values from the job itself
locaRepositoryToUse = mavenModuleProject.getLocalRepository();
settingsToUse = mavenModuleProject.getSettings();
globalSettingsToUse = mavenModuleProject.getGlobalSettings();
}
// Other properties
String additionalArguments = sonarInstallation.getAdditionalProperties();
String analysisProperties = StringUtils.join(sonarInstallation.getAdditionalAnalysisPropertiesUnix(), ' ');
String jobProperties = envVars.expand(sonarPublisher.getJobAdditionalProperties());
String additionalProperties = "" + (StringUtils.isNotBlank(additionalArguments) ? additionalArguments : "") + " " + (StringUtils.isNotBlank(analysisProperties) ? analysisProperties : "") + " " + (StringUtils.isNotBlank(jobProperties) ? jobProperties : "");
// Execute Maven
// SONARPLUGINS-487
String pomPath = build.getModuleRoot().child(pom).getRemote();
return new SonarMaven(additionalProperties, mavenName, pomPath, mvnOptions, locaRepositoryToUse, sonarPublisher, listener, jdk, settingsToUse, globalSettingsToUse).perform(build, launcher, listener);
}
use of hudson.EnvVars in project sonar-scanner-jenkins by SonarSource.
the class TriggersConfig method isSkipSonar.
public String isSkipSonar(AbstractBuild<?, ?> build, BuildListener listener) throws IOException, InterruptedException {
Result result = build.getResult();
if (result != null && result.isWorseThan(Result.UNSTABLE)) {
// unstable means that build completed, but there were some test failures, which is not critical for analysis
return Messages.SonarPublisher_BadBuildStatus(result.toString());
}
// skip analysis by environment variable or build parameter
if (getEnvVar() != null) {
// check against build parameters
String value = build.getBuildVariableResolver().resolve(getEnvVar());
if ("true".equalsIgnoreCase(value)) {
return Messages.Skipping_Sonar_analysis();
}
// check against environment variable
EnvVars envVars = build.getEnvironment(listener);
value = new VariableResolver.ByMap<>(envVars).resolve(getEnvVar());
if ("true".equalsIgnoreCase(value)) {
return Messages.Skipping_Sonar_analysis();
}
}
List<Cause> causes = new ArrayList<>(build.getCauses());
// skip analysis, when all causes from blacklist
if (isSkipScmCause() || isSkipUpstreamCause()) {
Iterator<Cause> iter = causes.iterator();
while (iter.hasNext()) {
Cause cause = iter.next();
if ((isSkipScmCause() && SCMTrigger.SCMTriggerCause.class.isInstance(cause)) || (isSkipUpstreamCause() && Cause.UpstreamCause.class.isInstance(cause))) {
iter.remove();
}
}
}
return causes.isEmpty() ? Messages.Skipping_Sonar_analysis() : null;
}
use of hudson.EnvVars in project promoted-builds-plugin by jenkinsci.
the class Promotion method getEnvironment.
@Override
public EnvVars getEnvironment(TaskListener listener) throws IOException, InterruptedException {
EnvVars e = super.getEnvironment(listener);
// Augment environment with target build's information
String rootUrl = Jenkins.get().getRootUrl();
AbstractBuild<?, ?> target = getTargetBuildOrFail();
if (rootUrl != null)
e.put("PROMOTED_URL", rootUrl + target.getUrl());
e.put("PROMOTED_JOB_NAME", target.getParent().getName());
e.put("PROMOTED_JOB_FULL_NAME", target.getParent().getFullName());
e.put("PROMOTED_NUMBER", Integer.toString(target.getNumber()));
e.put("PROMOTED_ID", target.getId());
GlobalBuildPromotedBuilds globalBuildPromotedBuilds = GlobalBuildPromotedBuilds.get();
String dateFormat = globalBuildPromotedBuilds.getDateFormat();
String timeZone = globalBuildPromotedBuilds.getTimeZone();
SimpleDateFormat format = null;
TimeZone tz = null;
if (dateFormat != null && !StringUtils.isBlank(dateFormat)) {
try {
format = new SimpleDateFormat(dateFormat);
} catch (IllegalArgumentException e1) {
LOGGER.log(Level.WARNING, String.format("An illegal date format was introduced: %s. Default ISO 8601 yyyy-MM-dd'T'HH:mmZ will be used", dateFormat), e1);
format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
}
} else {
// Per ISO 8601
format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
}
if (timeZone != null && !StringUtils.isBlank(timeZone)) {
try {
tz = TimeZone.getTimeZone(timeZone);
} catch (IllegalArgumentException e2) {
LOGGER.log(Level.WARNING, String.format("An illegal time zone was introduced: %s. Default GMT time zone will be used", timeZone), e2);
tz = TimeZone.getTimeZone("GMT");
}
} else {
tz = TimeZone.getTimeZone("GMT");
}
format.setTimeZone(tz);
e.put("PROMOTED_TIMESTAMP", format.format(new Date()));
e.put("PROMOTED_DISPLAY_NAME", target.getDisplayName());
e.put("PROMOTED_USER_NAME", getUserName());
e.put("PROMOTED_USER_ID", getUserId());
EnvVars envScm = new EnvVars();
target.getProject().getScm().buildEnvVars(target, envScm);
for (Entry<String, String> entry : envScm.entrySet()) {
e.put("PROMOTED_" + entry.getKey(), entry.getValue());
}
// Allow the promotion status to contribute to build environment
getStatus().buildEnvVars(this, e);
return e;
}
use of hudson.EnvVars in project promoted-builds-plugin by jenkinsci.
the class PromotionProcess method getDefaultParameterValuesAsEnvVars.
private static EnvVars getDefaultParameterValuesAsEnvVars(AbstractProject owner) {
EnvVars envVars = null;
ParametersDefinitionProperty parametersDefinitionProperty = (ParametersDefinitionProperty) owner.getProperty(ParametersDefinitionProperty.class);
if (parametersDefinitionProperty != null) {
envVars = new EnvVars();
for (ParameterDefinition parameterDefinition : parametersDefinitionProperty.getParameterDefinitions()) {
ParameterValue defaultParameterValue = parameterDefinition.getDefaultParameterValue();
if (defaultParameterValue != null) {
if (defaultParameterValue instanceof StringParameterValue) {
envVars.put(parameterDefinition.getName(), (String) defaultParameterValue.getValue());
}
}
}
EnvVars.resolve(envVars);
}
return envVars;
}
Aggregations