Skip to content

Commit

Permalink
[JENKINS-47823] workaround a bug in environment variable handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrille Le Clerc committed Nov 6, 2017
1 parent 5fc03e7 commit c16068a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Expand Up @@ -276,17 +276,13 @@ private void setupJDK() throws AbortException, IOException, InterruptedException

/**
* @param credentials list of credentials injected by withMaven. They will be tracked and masked in the logs.
* @throws AbortException
* @throws IOException
* @throws InterruptedException
*/
private void setupMaven(@Nonnull Collection<Credentials> credentials) throws AbortException, IOException, InterruptedException {
private void setupMaven(@Nonnull Collection<Credentials> credentials) throws IOException, InterruptedException {
// Temp dir with the wrapper that will be prepended to the path and the temporary files used by withMazven (settings files...)
tempBinDir = tempDir(ws).child("withMaven" + Util.getDigestOf(UUID.randomUUID().toString()).substring(0, 8));
tempBinDir.mkdirs();
// set the path to our script
envOverride.put("PATH+MAVEN", tempBinDir.getRemote());


// SETTINGS FILES
String settingsFilePath = setupSettingFile(credentials);
Expand All @@ -312,17 +308,17 @@ private void setupMaven(@Nonnull Collection<Credentials> credentials) throws Abo
//
// MAVEN_CONFIG
StringBuilder mavenConfig = new StringBuilder();
mavenConfig.append("--batch-mode ");
mavenConfig.append("--show-version ");
if (StringUtils.isNotEmpty(settingsFilePath)) {
mavenConfig.append(" --settings " + settingsFilePath);
mavenConfig.append("--settings " + settingsFilePath + " ");
}
if (StringUtils.isNotEmpty(globalSettingsFilePath)) {
mavenConfig.append(" --global-settings " + globalSettingsFilePath);
mavenConfig.append("--global-settings " + globalSettingsFilePath + " ");
}
if (StringUtils.isNotEmpty(mavenLocalRepo)) {
mavenConfig.append(" -Dmaven.repo.local=" + mavenLocalRepo);
mavenConfig.append("-Dmaven.repo.local=" + mavenLocalRepo + " ");
}
mavenConfig.append(" --batch-mode");
mavenConfig.append(" --show-version");

envOverride.put("MAVEN_CONFIG", mavenConfig.toString());

Expand Down Expand Up @@ -350,6 +346,10 @@ private void setupMaven(@Nonnull Collection<Credentials> credentials) throws Abo
FilePath mvnExec = new FilePath(ws.getChannel(), mvnExecPath);
String content = generateMavenWrapperScriptContent(mvnExec);

// ADD MAVEN WRAPPER SCRIPT PARENT DIRECTORY TO PATH
// WARNING MUST BE INVOKED AFTER obtainMavenExec(), THERE SEEM TO BE A BUG IN ENVIRONMENT VARIABLE HANDLING IN obtainMavenExec()
envOverride.put("PATH+MAVEN", tempBinDir.getRemote());

createWrapperScript(tempBinDir, mvnExec.getName(), content);

}
Expand Down
Expand Up @@ -599,7 +599,7 @@ public void maven_settings_path_defined_through_pipeline_attribute() throws Exce
"</project>'''\n" +
"\n" +
" withMaven(maven: 'apache-maven-3.5.0', mavenSettingsFilePath: 'maven-settings.xml') {\n" +
" sh 'mvn help:effective-settings'\n" +
" sh 'env && mvn help:effective-settings'\n" +
" }\n" +
"}\n";

Expand Down

0 comments on commit c16068a

Please sign in to comment.