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

    • 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
      ''')
      
      }
      

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

          Frederick Staats created issue -

          Can you please provide of the mvn "sh" script that would be needed with cygwin?

          Cyrille Le Clerc added a comment - Can you please provide of the mvn "sh" script that would be needed with cygwin?

          In the standard Maven distribution there is a "mvn" shell script and a "mvn.cmd" windows batch file.

          $ ls /c/Bretools/bretools-1.0.6/Maven/apache-maven-3.3.9/bin
          m2.conf mvn mvn.cmd mvnDebug mvnDebug.cmd mvnyjp

          When running Git bash on windows EITHER of these scripts will work on Windows to run Maven.  The issue i'm facing is with the wrappers that are created by Jenkins when using the withMaven() {} pipeline step.

          On when running inside a withMaven() { } configuration block the Jenkins updates the path to a Jenkins provided wrapper.  On non-windows it creates only a wrapper shell script called "mvn" that forwards to the shell script "mvn" inside the Maven tool directory.  On Windows it only creates is a "mvn.cmd" batch script wrapper that points to the Maven tool directory "mvn.cmd" batch script.  However in Git Bash that wrapper "mvn.cmd" is not a valid shell script so doesn't show up on the path as an executable script.  So as a work around I detect if we are on windows (COMSPEC environment variable is defined) and run mvn.cmd from a child batch script.

          The preferred solution would be that on Windows withMaven() {} create wrapper scripts for BOTH "mvn.cmd" which runs inside batch (CMD.EXE), and the "mvn" which runs in shells (e.g. BASH), the logic to do this exists but is currently only run on the non-windows hosts.

           

          Frederick Staats added a comment - In the standard Maven distribution there is a "mvn" shell script and a "mvn.cmd" windows batch file. $ ls /c/Bretools/bretools-1.0.6/Maven/apache-maven-3.3.9/bin m2.conf mvn mvn.cmd mvnDebug mvnDebug.cmd mvnyjp When running Git bash on windows EITHER of these scripts will work on Windows to run Maven.  The issue i'm facing is with the wrappers that are created by Jenkins when using the withMaven() {} pipeline step. On when running inside a withMaven() { } configuration block the Jenkins updates the path to a Jenkins provided wrapper.  On non-windows it creates only a wrapper shell script called "mvn" that forwards to the shell script "mvn" inside the Maven tool directory.  On Windows it only creates is a "mvn.cmd" batch script wrapper that points to the Maven tool directory "mvn.cmd" batch script.  However in Git Bash that wrapper "mvn.cmd" is not a valid shell script so doesn't show up on the path as an executable script.  So as a work around I detect if we are on windows (COMSPEC environment variable is defined) and run mvn.cmd from a child batch script. The preferred solution would be that on Windows withMaven() {} create wrapper scripts for BOTH "mvn.cmd" which runs inside batch (CMD.EXE), and the "mvn" which runs in shells (e.g. BASH), the logic to do this exists but is currently only run on the non-windows hosts.  

          Another clarification.  When on Windows inside bash you need to run "mvn" to run the shell script and "mvn.cmd" to run the batch shell script when running it from bash.  I would like to be able to always "mvn" inside a bash script regardless if I'm running on Windows or Linux.  What I'm trying to do is remove the need for end user platform specific code for a Maven build.  My snippet above used the boiler plate "$COMSPEC" //c mvn.cmd" but a simple "mvn.cmd" would have been sufficient.

          Please let me know if I'm not being clear.

          Frederick Staats added a comment - Another clarification.  When on Windows inside bash you need to run "mvn" to run the shell script and "mvn.cmd" to run the batch shell script when running it from bash.  I would like to be able to always "mvn" inside a bash script regardless if I'm running on Windows or Linux.  What I'm trying to do is remove the need for end user platform specific code for a Maven build.  My snippet above used the boiler plate "$COMSPEC" //c mvn.cmd" but a simple "mvn.cmd" would have been sufficient. Please let me know if I'm not being clear.
          Alvaro Lobato made changes -
          Assignee Original: Alvaro Lobato [ alobato ]

          flstaats I am not a Windows user, could you help with this?

          Cyrille Le Clerc added a comment - flstaats I am not a Windows user, could you help with this?

          @cleclerc sorry for the late response.  I've had some holiday (2017 American Eclipse!) and  I filed this from my personal rather than work account so it got lost it in the email.  Finally got caught up today.

          Yes I can help with this.  What kind of assistance would you like?

          Frederick Staats added a comment - @cleclerc sorry for the late response.  I've had some holiday (2017 American Eclipse!) and  I filed this from my personal rather than work account so it got lost it in the email.  Finally got caught up today. Yes I can help with this.  What kind of assistance would you like?
          Cyrille Le Clerc made changes -
          Link New: This issue is related to JENKINS-44276 [ JENKINS-44276 ]
          Cyrille Le Clerc made changes -
          Description Original: 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''')

          }
          New: 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']) \{

           
          {code}
          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''')

          }
          {code}
          Cyrille Le Clerc made changes -
          Description Original: 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']) \{

           
          {code}
          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''')

          }
          {code}
          New: 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:

          {code}
          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''')

          }
          {code}

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

              Created:
              Updated: