Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-31986

OS-related problems with Maven parameters (from job or from build step)

XMLWordPrintable

      The issue is partially related to both:

      TL;DR

      This issue only happens on Windows, and is closely related to how the Maven executable is called, and how that execution works when spaces are involved. Thus in my opinion it's a bug of the Jenkins' Maven plugin, as a manual call to Maven in a prompt works OK.

      Please note that this bug is blocking in a very common use-case (maven-release-plugin taking arguments from the command line). I hope you can fix it soon...

      We use the maven-release-plugin in one of our jobs and we have two parameters to the job "releaseVersion" and "developmentVersion" (cf. maven-release-plugin documentation for more details). With the maven-release-plugin there is the need to pass parameters from the mvn.exe executed by Jenkins to the underlying mvn.exe launched by the plugin itself (maven-release-plugin executes its own new mvn.exe). This is a very common use-case.

      Here's what it looks like if I launch it on my computer:

      mvn -DdevelopmentVersion=2.1-SNAPSHOT -DreleaseVersion=2.0 -Dtag=2.0 -DautoVersionSubmodules=true "-Darguments=-Dtag=2.0 -DreleaseVersion=2.0 -DdevelopmentVersion=2.1-SNAPSHOT" release:prepare release:perform
      

      As you can see i have to surround the "arguments" property's value with double-quotes because every parameter inside this value is space-separated.

      But if i try to do that in Jenkins it fails. To be clear, here's what i provide to the Maven build step as the properties and goals :

      • job parameters : releaseVersion and developmentVersion
      • goals : -B -U release:prepare release:perform
      • properties :
        tag=$releaseVersion
        arguments=-Dtag=$releaseVersion -DreleaseVersion=$releaseVersion -DdevelopmentVersion=$developmentVersion
        

      And here's the log:

      [workspace] $ cmd.exe /C '"C:\bin\tools\apache-maven-3.2.5\bin\mvn.bat -DdevelopmentVersion=2.1-SNAPSHOT -DreleaseVersion=2.0 -Dtag=2.0 "-Darguments=-Dtag=2.0 -DreleaseVersion=2.0 -DdevelopmentVersion=2.1-SNAPSHOT" -B -U release:prepare release:perform && exit %%ERRORLEVEL%%"'
      ...
      Unknown lifecycle phase "2.1-SNAPSHOT".
      

      As you can see, the call made to cmd.exe surrounds the command to be launched by single-quotes AND double-quotes. And as a consequence, any double quotes inside that command are breaking the behaviour. The double-quotes surrounding "-Darguments" and its value make the parsing fail.

      In order to work properly i think only the executable should be surrounded by double-quotes in the /C flag of cmd.exe. Here's what I expect to work:

      cmd.exe /C '"C:\bin\tools\apache-maven-3.2.5\bin\mvn.bat" -DdevelopmentVersion=2.1-SNAPSHOT -DreleaseVersion=2.0 -Dtag=2.0 "-Darguments=-Dtag=2.0 -DreleaseVersion=2.0 -DdevelopmentVersion=2.1-SNAPSHOT" -B -U release:prepare release:perform && exit %%ERRORLEVEL%%'
      

      Thanks for your help.

            Unassigned Unassigned
            bardelotnzl Noël Bardelot
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: