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

[cygwin] Request that withMaven pipeline step produce both mvn and mvn.cmd wrappers on Windows

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • pipeline-maven-plugin

      Request that withMaven pipeline step produce both mvn and mvn.cmd wrappers on Windows.

      On Windows build agents we would like the withMaven build step to produce wrappers that work for both bash.exe and cmd.exe.  Currently the step adds a directory that adds a script "mvn" on Linux and adds a script "mvn.cmd" on Windows.  On Windows it is possible to configure the build server to make available the Git for Windows tool suite which includes bash.exe.  We write all of our build scripts in bash syntax so that we can be cross platform on build agents when doing builds that are platform agnostic, like running Java based Maven builds.

      We have a work around (see code below) that allows us to do the the build by calling "$COMSPEC" to execute the mvn.cmd.  It would be simpler and cleaner if the both a bash.exe compatible "mvn" wrapper and cmd.exe compatible "mvn.cmd" wrapper were produced on the Windows Platform.  Note the Git for Windows bash.exe accepts both Unix style paths (/c/Program\ Files, or '/c/Program Files') and Windows style paths (C:\\Program\ Files, or 'C:\Program Files') as long as they are properly escaped or quoted.

      When running a withMaven build from a sh() build step on Windows this is our current work around:

      withMaven(
         jdk: config['jdk'], 
         maven: config['maven'], 
         mavenLocalRepo: config['mavenLocalRepo'], 
         mavenSettingsConfig: config['mavenSettingsConfig']) {
      
      sh('''
      
      if [[ -e "pom.xml" ]]; then
           # Run Jenkins maven wrapper script using mvn in Unix bash 
           # or mvn.cmd in cmd.exe from Git for Windows bash
      
           if [[ -z "$COMSPEC" ]]; then
               cmd=(mvn)
           else
               cmd=("$COMSPEC" //c mvn.cmd)
           fi
           args=(--batch-mode -U -V --settings "$MVN_SETTINGS" clean install -P "$BUILD_PROFILE" 
               "-DxlDeployServerAddress=$XLDEPLOY_SERVER_ADDRESS" "-DxlDeployPort=$XLDEPLOY_PORT" 
               "-DxlDeploySecured=$XLDEPLOY_SECURED" "-DbuildUrl=$BUILD_URL")
           eval $(printf " %q" "$\{cmd[@]}" "$\{args[@]}")
       fi
      ''')
      
      }
      

            Unassigned Unassigned
            flstaats Frederick Staats
            Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: