Make dockerized pipelines executable when running Jenkins on a Windows platform (e.g. for testing purposes when no Unix box is at hand).

      When running Docker-Toolbox on Windows, the "docker" command is available, but the plugin fails to invoke it because it uses the pipeline "sh" command (see https://github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL.md#modifying-for-windows-variations)

      java.io.IOException: Cannot run program "nohup" (in directory "d:\dev\jenkins\local\data\workspace\multibranch\master"): CreateProcess error=2, Das System kann die angegebene Datei nicht finden
      	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
      [...]
      	at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/d:/dev/jenkins/local/data/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:106)
      	at org.jenkinsci.plugins.docker.workflow.Docker.node(jar:file:/d:/dev/jenkins/local/data/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:63)
      	at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/d:/dev/jenkins/local/data/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:104)
      	at WorkflowScript.run(WorkflowScript:4)
      [...]
      

          [JENKINS-34454] Add support for Docker-Toolbox/Windows

          Jesse Glick added a comment -

          Unfortunately I tried to install Toolbox in Windows 10 inside VirtualBox without success, so I have no ability to test patches.

          Jesse Glick added a comment - Unfortunately I tried to install Toolbox in Windows 10 inside VirtualBox without success, so I have no ability to test patches.

          Marvel Zeng added a comment -

          you want to use "sh" on windows platform, you should add e.g. C:\Program Files\Git\usr\bin to the PATH.

          Marvel Zeng added a comment - you want to use "sh" on windows platform, you should add e.g. C:\Program Files\Git\usr\bin to the PATH.

          marvel thanks for a hint, that works in windows

          Alexander Siniouguine added a comment - marvel thanks for a hint, that works in windows

          Liam Newman added a comment - - edited

          There are a number of issues linked to https://issues.jenkins-ci.org/browse/JENKINS-36776.

           

          I'm trying to run the a Pipeline on a Windows machine with docker for windows installed. 

          What I have done:

          1. Created a windows 10 Pro VM on Azure using the "Standard D4s v3" image (which supports virtualization and Hyper-V)
          2. Install Docker CE for Windows - This will automatically enable HyperV and reboot the VM to complete.
          3. Changed Docker (in the taskbar icon menu) to "Switch to Windows Containers"
          4. Install JDK 8 from Oracle
          5. Downloaded "Jenkins WAR package"
          6. Installed git-scm to get the git-bash command prompt
          7. Open git-bash and run "java -jar jenkins.war" - This works around https://issues.jenkins-ci.org/browse/JENKINS-34454 by providing access to "sh" and related commands on the host.
          8. Attempt to run the following pipeline:

           

          pipeline {
            agent {
              docker {
                image 'microsoft/nanoserver'
              }
            }
            stages {
              stage('Build') {
                steps {
                  echo "Docker success"
                }
              }
            }
           }
          

           

           

          Result:

          Started by user bitwiseman
           Replayed #10
           Running in Durability level: MAX_SURVIVABILITY
           [Pipeline] node
           Running on Jenkins in C:\Users\lnewman\.jenkins\workspace\pipeline-test
           [Pipeline] {
           [Pipeline] stage
           [Pipeline] { (Declarative: Agent Setup)
           [Pipeline] sh
           [C:\Users\lnewman\.jenkins\workspace\pipeline-test] Running shell script
           + docker pull microsoft/nanoserver
           Using default tag: latest
           latest: Pulling from microsoft/nanoserver
           Digest: sha256:3d2948c5af9f4bece59b13f199f5bec59d6dc4930fb15aa9b6a223d2ea8d8471
           Status: Image is up to date for microsoft/nanoserver:latest
           [Pipeline] }
           [Pipeline] // stage
           [Pipeline] sh
           [C:\Users\lnewman\.jenkins\workspace\pipeline-test] Running shell script
           + docker inspect -f . microsoft/nanoserver
           .
           [Pipeline] withDockerContainer
           Jenkins does not seem to be running inside a container
           $ docker run -t -d -u 197108:197121 -w C:\Users\lnewman\.jenkins\workspace\pipeline-test -v C:\Users\lnewman\.jenkins\workspace\pipeline-test:C:\Users\lnewman\.jenkins\workspace\pipeline-test:rw,z -v C:\Users\lnewman\.jenkins\workspace\pipeline-test@tmp:C:\Users\lnewman\.jenkins\workspace\pipeline-test@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** microsoft/nanoserver cat
           [Pipeline] // withDockerContainer
           [Pipeline] }
           [Pipeline] // node
           [Pipeline] End of Pipeline
           java.io.IOException: Failed to run image 'microsoft/nanoserver'. Error: docker: Error response from daemon: invalid volume specification: 'C:\Users\lnewman\.jenkins\workspace\pipeline-test:C:\Users\lnewman\.jenkins\workspace\pipeline-test:rw,z'.
           See 'docker run --help'.
           ...

          This indicates that it might be possible to run containers directly but the built-in docker plugin bugs are still blocking.

          Liam Newman added a comment - - edited There are a number of issues linked to https://issues.jenkins-ci.org/browse/JENKINS-36776 .   I'm trying to run the a Pipeline on a Windows machine with docker for windows installed.  What I have done: Created a windows 10 Pro VM on Azure using the "Standard D4s v3" image (which supports virtualization and Hyper-V) Install Docker CE for Windows - This will automatically enable HyperV and reboot the VM to complete. Changed Docker (in the taskbar icon menu) to "Switch to Windows Containers" Install JDK 8 from Oracle Downloaded "Jenkins WAR package" Installed git-scm to get the git-bash command prompt Open git-bash and run "java -jar jenkins.war" - This works around https://issues.jenkins-ci.org/browse/JENKINS-34454 by providing access to "sh" and related commands on the host. Attempt to run the following pipeline:   pipeline {   agent {     docker {       image 'microsoft/nanoserver'     }   }   stages {     stage('Build') {       steps {         echo "Docker success"       }     }   } }     Result: Started by user bitwiseman Replayed #10 Running in Durability level: MAX_SURVIVABILITY [Pipeline] node Running on Jenkins in C:\Users\lnewman\.jenkins\workspace\pipeline-test [Pipeline] { [Pipeline] stage [Pipeline] { (Declarative: Agent Setup) [Pipeline] sh [C:\Users\lnewman\.jenkins\workspace\pipeline-test] Running shell script + docker pull microsoft/nanoserver Using default tag: latest latest: Pulling from microsoft/nanoserver Digest: sha256:3d2948c5af9f4bece59b13f199f5bec59d6dc4930fb15aa9b6a223d2ea8d8471 Status: Image is up to date for microsoft/nanoserver:latest [Pipeline] } [Pipeline] // stage [Pipeline] sh [C:\Users\lnewman\.jenkins\workspace\pipeline-test] Running shell script + docker inspect -f . microsoft/nanoserver . [Pipeline] withDockerContainer Jenkins does not seem to be running inside a container $ docker run -t -d -u 197108:197121 -w C:\Users\lnewman\.jenkins\workspace\pipeline-test -v C:\Users\lnewman\.jenkins\workspace\pipeline-test:C:\Users\lnewman\.jenkins\workspace\pipeline-test:rw,z -v C:\Users\lnewman\.jenkins\workspace\pipeline-test@tmp:C:\Users\lnewman\.jenkins\workspace\pipeline-test@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** microsoft/nanoserver cat [Pipeline] // withDockerContainer [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline java.io.IOException: Failed to run image 'microsoft/nanoserver'. Error: docker: Error response from daemon: invalid volume specification: 'C:\Users\lnewman\.jenkins\workspace\pipeline-test:C:\Users\lnewman\.jenkins\workspace\pipeline-test:rw,z'. See 'docker run --help'. ... This indicates that it might be possible to run containers directly but the built-in docker plugin bugs are still blocking.

          Just curious. Any luck on making any progress on this or is this a feature that I won't see for any time in the foreseeable future?

          I just want to adjust my hype expectations appropriately.

          Henry Borchers added a comment - Just curious. Any luck on making any progress on this or is this a feature that I won't see for any time in the foreseeable future? I just want to adjust my hype expectations appropriately.

          I am also trying to run a linux docker container on windows slave, and getting the same "nohup" error. When will this be fixed?

          yacoub hossain added a comment - I am also trying to run a linux docker container on windows slave, and getting the same "nohup" error. When will this be fixed?

          I'm guessing it's going to be a long time before we see Windows support since it doesn't look like anybody is working on this and it seems like it's low priority. 

          Henry Borchers added a comment - I'm guessing it's going to be a long time before we see Windows support since it doesn't look like anybody is working on this and it seems like it's low priority. 

          I made some research on this, because we need windows containers in our build chain and I came to this findings:

          The nohup isn't a big deal, because you can work around it by installing a sh environment on windows (e.g. git with git-scm and add C:\Program Files\Git\usr\bin to the PATH variable).

          This isn't a nice workaround, but the real problem is the way Jenkins calls docker!

          Jenkins passes a "z" flag in the volume description, which isn't supported by docker for windows and throws an error.

          Fixing this, I tried to write a bat and a sh script, which remove the "z" flag and naming them "docker.bat" and "docker" (I renamed docker.exe to docker-client.exe). Running from sh and cmd I was able to run all docker commands, but Jenkins complained about not finding the file.

           

          Caused: java.io.IOException: Cannot run program "docker": CreateProcess error=2, The system cannot find the file specified
          

           

          In general I think, that the plugin shouldn't provide the "z" flag outside of an SELinnux environment and that would solve the problem.

          Raphael Höser added a comment - I made some research on this, because we need windows containers in our build chain and I came to this findings: The nohup isn't a big deal, because you can work around it by installing a sh environment on windows (e.g. git with  git-scm  and add C:\Program Files\Git\usr\bin to the PATH variable). This isn't a nice workaround, but the real problem is the way Jenkins calls docker! Jenkins passes a "z" flag in the volume description, which isn't supported by docker for windows and throws an error. Fixing this, I tried to write a bat and a sh script, which remove the "z" flag and naming them "docker.bat" and "docker" (I renamed docker.exe to docker-client.exe). Running from sh and cmd I was able to run all docker commands, but Jenkins complained about not finding the file.   Caused: java.io.IOException: Cannot run program "docker" : CreateProcess error=2, The system cannot find the file specified   In general I think, that the plugin shouldn't provide the "z" flag outside of an SELinnux environment and that would solve the problem.

            jglick Jesse Glick
            martoe Martin E
            Votes:
            11 Vote for this issue
            Watchers:
            17 Start watching this issue

              Created:
              Updated: