Skip to content

Commit

Permalink
[JENKINS-48264] Support whitespace in pipeline name (#111)
Browse files Browse the repository at this point in the history
[JENKINS-48264] Support whitespaces in pipeline name
  • Loading branch information
Cyrille Le Clerc committed Dec 3, 2017
1 parent c6c1267 commit c599a50
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
Expand Up @@ -321,13 +321,13 @@ private void setupMaven(@Nonnull Collection<Credentials> credentials) throws IOE
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 + "\" ");
}

envOverride.put("MAVEN_CONFIG", mavenConfig.toString());
Expand All @@ -354,7 +354,7 @@ private void setupMaven(@Nonnull Collection<Credentials> credentials) throws IOE
}

FilePath mvnExec = new FilePath(ws.getChannel(), mvnExecPath);
String content = generateMavenWrapperScriptContent(mvnExec);
String content = generateMavenWrapperScriptContent(mvnExec, mavenConfig.toString());

// 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()
Expand Down Expand Up @@ -545,10 +545,11 @@ private String readFromProcess(String... args) throws InterruptedException {
* Generates the content of the maven wrapper script
*
* @param mvnExec maven executable location
* @param mavenConfig config arguments added to the "mvn" command line
* @return wrapper script content
* @throws AbortException when problems creating content
*/
private String generateMavenWrapperScriptContent(FilePath mvnExec) throws AbortException {
private String generateMavenWrapperScriptContent(@Nonnull FilePath mvnExec, @Nonnull String mavenConfig) throws AbortException {

boolean isUnix = Boolean.TRUE.equals(getComputer().isUnix());

Expand All @@ -558,13 +559,13 @@ private String generateMavenWrapperScriptContent(FilePath mvnExec) throws AbortE
String lineSep = "\n";
script.append("#!/bin/sh -e").append(lineSep);
script.append("echo ----- withMaven Wrapper script -----").append(lineSep);
script.append(mvnExec.getRemote() + " $MAVEN_CONFIG \"$@\"").append(lineSep);
script.append(mvnExec.getRemote() + " " + mavenConfig + " \"$@\"").append(lineSep);

} else { // Windows
String lineSep = "\r\n";
script.append("@echo off").append(lineSep);
script.append("echo ----- withMaven Wrapper script -----").append(lineSep);
script.append(mvnExec.getRemote() + " %MAVEN_CONFIG% %*").append(lineSep);
script.append(mvnExec.getRemote() + " " + mavenConfig + " %*").append(lineSep);
}

LOGGER.log(Level.FINER, "Generated Maven wrapper script: \n{0}", script);
Expand Down
Expand Up @@ -59,6 +59,7 @@
import org.junit.Test;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.ExtendedToolInstallations;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

import java.io.File;
Expand Down Expand Up @@ -166,6 +167,47 @@ public void maven_build_jar_project_on_master_succeeds() throws Exception {
assertThat(tasksResultAction.getProjectActions().size(), is(1));
}

@Issue("JENKINS-48264")
@Test
public void maven_build_jar_project_with_whitespace_char_in_name() throws Exception {
loadMavenJarProjectInGitRepo(this.gitRepoRule);

String pipelineScript = "node('master') {\n" +
" git($/" + gitRepoRule.toString() + "/$)\n" +
" withMaven() {\n" +
" sh 'mvn help:effective-settings'\n" +
" }\n" +
"}";

String mavenSettings = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<settings \n" +
" xmlns='http://maven.apache.org/SETTINGS/1.0.0'\n" +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n" +
" xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'>\n" +
" <servers>\n" +
" <server>\n" +
" <id>id-settings-test-through-config-file-provider</id>\n" +
" </server>\n" +
" </servers>\n" +
"</settings>\n";
MavenSettingsConfig mavenSettingsConfig = new MavenSettingsConfig("maven-config-test", "maven-config-test", "", mavenSettings, false, null);

GlobalConfigFiles.get().save(mavenSettingsConfig);
GlobalMavenConfig.get().setSettingsProvider(new MvnSettingsProvider(mavenSettingsConfig.id));


try {
WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, "build on master with spaces");
pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));
jenkinsRule.assertLogContains("[withMaven] use Maven settings provided by the Jenkins global configuration", build);
jenkinsRule.assertLogContains("<id>id-settings-test-through-config-file-provider</id>", build);
} finally {
GlobalMavenConfig.get().setSettingsProvider(null);
}

}

@Test
public void maven_build_jar_project_on_master_disable_findbugs_publisher_succeeds() throws Exception {
maven_build_jar_project_on_master_with_disabled_publisher_param_succeeds(new FindbugsAnalysisPublisher.DescriptorImpl(), "findbugsPublisher", true);
Expand Down

0 comments on commit c599a50

Please sign in to comment.