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

Durable task plugin on Windows fails to run jenkins-wrapper.bat if workspace has a space

      If the path to the Jenkins workspace folder has a space in Windows the space is not properly handled when launching a Windows docker container with the docker workflow plugin.

      Docker Desktop Version: 27.2.0
      Image: mcr.microsoft.com/windows/nanoserver:ltsc2019

      This can be reproduced by running docker for windows through a unit test.

      Command:

      docker exec --workdir C:\git\docker-workflow-plugin\target\tmp\j h14592559048553421565\workspace\prj <. . .> 98037c1c32a7ca4b27e54256097b8d3c45e5629581921e606e1bbe6204b02bc9 cmd /c ""C:\git\docker-workflow-plugin\target\tmp\j h14592559048553421565\workspace\prj@tmp\durable-33850330\jenkins-wrap.bat""
      

      Response:

      'C:\git\docker-workflow-plugin\target\tmp\j\' is not recognized as an internal or external command,
      operable program or batch file.
      

      There are two defects here:
      1) The workdir needs to be quoted here
      2) The consecutive double quotes ("") used when launching jenkins-wrapper.bat doesn't work with docker exec here

      After experimenting it looks like the "cmd /c call" approach already used by the jenkins-wraper.bat works:

      docker exec --workdir C:\git\docker-workflow-plugin\target\tmp\j h14592559048553421565\workspace\prj <. . .> 98037c1c32a7ca4b27e54256097b8d3c45e5629581921e606e1bbe6204b02bc9 cmd /c call "C:\git\docker-workflow-plugin\target\tmp\j h14592559048553421565\workspace\prj@tmp\durable-33850330\jenkins-wrap.bat"
      

          [JENKINS-75102] Durable task plugin on Windows fails to run jenkins-wrapper.bat if workspace has a space

          Mark R added a comment - - edited

          The problem seems to be how docker is handling the double quotes.

          Example:
          1. Create "C:/temp/folder with spaces/myscript.bat" with the contents "echo hi"
          2. docker run -d -t -v "C:\temp\folder with spaces:C:\temp\folder with spaces" mcr.microsoft.com/windows/nanoserver:ltsc2019 (or some other tag that matches the Windows kernel)
          3. docker exec <id> cmd /c ""C:\temp\folder with spaces\myscript.bat""

          Output:

          'C:\temp\folder' is not recognized as an internal or external command,
          operable program or batch file.
          

          By setting DOCKER_HOST=tcp://localhost:2375 the REST call can be captured. Here is the body sent in:

          {
              "User": "",
              "Privileged": false,
              "Tty": false,
              "AttachStdin": false,
              "AttachStderr": true,
              "AttachStdout": true,
              "Detach": false,
              "DetachKeys": "",
              "Env": null,
              "WorkingDir": "",
              "Cmd": ["cmd", "/c", "C:\\temp\\folder", "with", "spaces\\myscript.bat"]
          }
          

          Mark R added a comment - - edited The problem seems to be how docker is handling the double quotes. Example: 1. Create "C:/temp/folder with spaces/myscript.bat" with the contents "echo hi" 2. docker run -d -t -v "C:\temp\folder with spaces:C:\temp\folder with spaces" mcr.microsoft.com/windows/nanoserver:ltsc2019 (or some other tag that matches the Windows kernel) 3. docker exec <id> cmd /c ""C:\temp\folder with spaces\myscript.bat"" Output: 'C:\temp\folder' is not recognized as an internal or external command, operable program or batch file. By setting DOCKER_HOST=tcp://localhost:2375 the REST call can be captured. Here is the body sent in: { "User" : "", "Privileged" : false , "Tty" : false , "AttachStdin" : false , "AttachStderr" : true , "AttachStdout" : true , "Detach" : false , "DetachKeys" : "", "Env" : null , "WorkingDir" : "", "Cmd" : [ "cmd" , "/c" , "C:\\temp\\folder" , "with" , "spaces\\myscript.bat" ] }

          Mark R added a comment - - edited

          Quote escaping between cmd, docker, and container cmd is tricky. It's easier just to try different combinations:

          OK: docker exec 8796e cmd /c "C:\temp\folder with spaces\myscript.bat"

          "Cmd": ["cmd", "/c", "C:\\temp\\folder with spaces\\myscript.bat"]
          

          FAIL: docker exec 8796e cmd /c ""C:\temp\folder with spaces\myscript.bat""

          "Cmd": ["cmd", "/c", "C:\\temp\\folder", "with", "spaces\\myscript.bat"]
          

          FAIL: docker exec 8796e cmd /c """C:\temp\folder with spaces\myscript.bat"""

          ["cmd", "/c", "\"C:\\temp\\folder", "with", "spaces\\myscript.bat\""]
          

          FAIL: docker exec 8796e cmd /c """"C:\temp\folder with spaces\myscript.bat""""

          ["cmd", "/c", "\"C:\\temp\\folder with spaces\\myscript.bat\""]
          

          FAIL: docker exec 8796e cmd /c """""C:\temp\folder with spaces\myscript.bat"""""

          ["cmd", "/c", "\"\"C:\\temp\\folder", "with", "spaces\\myscript.bat\"\""]
          

          different error: The network path was not found.

          Mark R added a comment - - edited Quote escaping between cmd, docker, and container cmd is tricky. It's easier just to try different combinations: OK: docker exec 8796e cmd /c "C:\temp\folder with spaces\myscript.bat" "Cmd" : [ "cmd" , "/c" , "C:\\temp\\folder with spaces\\myscript.bat" ] FAIL: docker exec 8796e cmd /c ""C:\temp\folder with spaces\myscript.bat"" "Cmd" : [ "cmd" , "/c" , "C:\\temp\\folder" , "with" , "spaces\\myscript.bat" ] FAIL: docker exec 8796e cmd /c """C:\temp\folder with spaces\myscript.bat""" [ "cmd" , "/c" , "\" C:\\temp\\folder ", " with ", " spaces\\myscript.bat\""] FAIL: docker exec 8796e cmd /c """"C:\temp\folder with spaces\myscript.bat"""" [ "cmd" , "/c" , "\" C:\\temp\\folder with spaces\\myscript.bat\""] FAIL: docker exec 8796e cmd /c """""C:\temp\folder with spaces\myscript.bat""""" [ "cmd" , "/c" , "\" \ "C:\\temp\\folder" , "with" , "spaces\\myscript.bat\" \""] different error: The network path was not found.

          Mark R added a comment - - edited

          Things get even more tricky when there is a space in a folder name and a '@' character.

          FAIL: docker exec 8796e cmd /c "C:\temp\folder with spaces\prj@tmp\myscript.bat"

          ["cmd", "/c", "C:\\temp\\folder with spaces\\prj@tmp\\myscript.bat"]
          

          FAIL: docker exec 8796e cmd /c ""C:\temp\folder with spaces\prj@tmp\myscript.bat""

          ["cmd", "/c", "C:\\temp\\folder", "with", "spaces\\prj@tmp\\myscript.bat"]
          

          Mark R added a comment - - edited Things get even more tricky when there is a space in a folder name and a '@' character. FAIL: docker exec 8796e cmd /c "C:\temp\folder with spaces\prj@tmp\myscript.bat" [ "cmd" , "/c" , "C:\\temp\\folder with spaces\\prj@tmp\\myscript.bat" ] FAIL: docker exec 8796e cmd /c ""C:\temp\folder with spaces\prj@tmp\myscript.bat"" [ "cmd" , "/c" , "C:\\temp\\folder" , "with" , "spaces\\prj@tmp\\myscript.bat" ]

          Mark R added a comment -

          Mark R added a comment - PR - https://github.com/jenkinsci/docker-workflow-plugin/pull/326

            mrichar2 Mark R
            mrichar2 Mark R
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: