Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-47823] expose the MVN_CMD_DIR environment variable to prepen…
…d it to the PATH
  • Loading branch information
Cyrille Le Clerc committed Nov 9, 2017
1 parent b289f40 commit 556c800
Showing 1 changed file with 11 additions and 3 deletions.
Expand Up @@ -109,7 +109,14 @@ class WithMavenStepExecution extends StepExecution {
private static final String M2_HOME = "M2_HOME";
private static final String MAVEN_HOME = "MAVEN_HOME";
private static final String MAVEN_OPTS = "MAVEN_OPTS";
/**
* Environment variable of the path to the wrapped "mvn" command, you can just invoke "$MVN_CMD clean package"
*/
private static final String MVN_CMD = "MVN_CMD";
/**
* Environment variable of the path to the parent folder of the wrapper of the "mvn" command, you can add it to the "PATH" with "export PATH=$MVN_CMD_DIR:$PATH"
*/
private static final String MVN_CMD_DIR = "MVN_CMD_DIR";

private static final Logger LOGGER = Logger.getLogger(WithMavenStepExecution.class.getName());

Expand Down Expand Up @@ -175,13 +182,13 @@ public boolean start() throws Exception {

if (withContainer) {
listener.getLogger().print("[withMaven] WARNING: \"withMaven(){...}\" step running within \"docker.image('image').inside {...}\"." +
" Since the Docker Pipeline Plugin version 1.14, you MUST prepend the 'MVN_CMD' environment variable" +
" Since the Docker Pipeline Plugin version 1.14, you MUST prepend the 'MVN_CMD_DIR' environment variable" +
" to the 'PATH' environment variable in every 'sh' step that invokes 'mvn'. ");
listener.getLogger().print("See ");
listener.hyperlink("https://wiki.jenkins.io/display/JENKINS/Pipeline+Maven+Plugin#PipelineMavenPlugin-HowtousethePipelineMavenPluginwithDocker", "Pipeline Maven Plugin FAQ");
listener.getLogger().println(".");
listener.getLogger().println("[withMaven] Sample:");
listener.getLogger().println("[withMaven] sh \"export PATH=$MVN_CMD:$PATH && mvn ...\"");
listener.getLogger().println("[withMaven] sh \"export PATH=$MVN_CMD_DIR:$PATH && mvn ...\"");
}

setupJDK();
Expand Down Expand Up @@ -280,9 +287,10 @@ private void setupJDK() throws AbortException, IOException, InterruptedException
* @throws 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...)
// Temp dir with the wrapper that will be prepended to the path and the temporary files used by withMaven (settings files...)
tempBinDir = tempDir(ws).child("withMaven" + Util.getDigestOf(UUID.randomUUID().toString()).substring(0, 8));
tempBinDir.mkdirs();
envOverride.put("MVN_CMD_DIR", tempBinDir.getRemote());

// SETTINGS FILES
String settingsFilePath = setupSettingFile(credentials);
Expand Down

0 comments on commit 556c800

Please sign in to comment.