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

Unable to run a bat step if the double-quoted path argument contains whitespace

    Details

    • Similar Issues:

      Description

      I run Jenkins 2.0 beta binary under Windows 10.
      Following tutorial in https://github.com/jenkinsci/workflow-plugin/blob/master/TUTORIAL.md,
      I created a pipeline job with the following script:

      node {
        git url: 'https://github.com/jglick/simple-maven-project-with-tests.git'
        def mvnHome = tool 'M3'
        bat "${mvnHome}\\bin\\mvn -B verify"
      }
      

      I get the following error when running the job:

      Started by user Administrateur
      [Pipeline] Allocate node : Start
      Running on master in C:\Program Files (x86)\Jenkins\workspace\myPipeline
      [Pipeline] node {
      [Pipeline] git
      Cloning the remote Git repository
      remote: Counting objects
      Receiving objects
      Resolving deltas
      Updating references
      Checking out Revision 7dac409d4bd2fec35a4ccde0cb424042cba671df (refs/remotes/origin/master)
      First time build. Skipping changelog.
      [Pipeline] tool
      Unpacking http://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip to C:\Program Files (x86)\Jenkins\tools\hudson.tasks.Maven_MavenInstallation\M3 on Jenkins
      [Pipeline] bat
      [myPipeline] Running batch script
      
      C:\Program Files (x86)\Jenkins\workspace\myPipeline>C:\Program Files (x86)\Jenkins\tools\hudson.tasks.Maven_MavenInstallation\M3\bin\mvn -B verify 
      'C:\Program' is not recognized as internal or external command, an executable program or a commands file.
      [Pipeline] } //node
      [Pipeline] Allocate node : End
      [Pipeline] End of Pipeline
      ERROR: script returned exit code 1
      Finished: FAILURE
      

      Workaround: I have to surround ${mvnHome} reference between escaped double quote:

      node {
        git url: 'https://github.com/jglick/simple-maven-project-with-tests.git'
        def mvnHome = tool 'M3'
        bat "\"${mvnHome}\"\\bin\\mvn -B verify"
      }
      

        Attachments

          Activity

          Hide
          danielbeck Daniel Beck added a comment - - edited

          This seems to be a weird interaction between our Windows installer (C:\ProgramData anyone?), tool installers, and Pipeline.

          Jesse Glick Any ideas?

          Show
          danielbeck Daniel Beck added a comment - - edited This seems to be a weird interaction between our Windows installer ( C:\ProgramData anyone?), tool installers, and Pipeline. Jesse Glick Any ideas?
          Hide
          jglick Jesse Glick added a comment -

          If your path might include spaces, you would need to include extra quotes around it.

          Show
          jglick Jesse Glick added a comment - If your path might include spaces, you would need to include extra quotes around it.
          Hide
          kvijay460 Vijay K added a comment -

          Jesse Glick Can you give me an example code snippet.

          I did put quotes around the command but it didn't work.

          example: "C:\Program Files\Git\cmd\git.exe"

          Show
          kvijay460 Vijay K added a comment - Jesse Glick Can you give me an example code snippet. I did put quotes around the command but it didn't work. example:  "C:\Program Files\Git\cmd\git.exe"
          Hide
          jglick Jesse Glick added a comment -

          Vijay K sounds like a question for the users’ list or similar.

          Show
          jglick Jesse Glick added a comment - Vijay K sounds like a question for the users’ list or similar.

            People

            • Assignee:
              jglick Jesse Glick
              Reporter:
              lautou Laurent TOURREAU
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: