Using Docker for Windows in Jenkins Declarative Pipeline

…衆ロ難τιáo~ 提交于 2021-02-07 21:50:18

问题


I am setting up a CI workflow with Jenkins declarative pipeline and Docker-for-Windows agents through Dockerfile.

Note: It is unfortunately currently not a solution to use a Linux-based docker daemon, since I need to run Windows binaries.

Setup: Jenkins master runs on Linux 16.04 through Docker. Jenkins build agent is

  • Windows 10 Enterprise 1709 (16299.551)
  • Docker-for-Windows 17.12.0-ce

Docker 18.x gave me headaches when trying to use Windows Containers, so I rolled back to 17.x. I still had some issues when trying to run with Jenkins and nohup not being on path, but it was solved by adding Git binaries to Windows search path (another reference). I suspect my current issue may be related.

Code: I am trying to initialize a Jenkinsfile and run a simple hello-world-printout within.

/Jenkinsfile

pipeline {
  agent none
  stages {
    stage('Docker Test') {
      agent {
        dockerfile {
          filename 'Dockerfile'
          label 'windocker'
        }
      }
      steps {
        println 'Hello, World!'
      }
    }
  }
}

/Dockerfile

FROM python:3.7-windowsservercore
RUN python -m pip install --upgrade pip

Basically, this should be a clean image that simply prints "Hello, World!". But it fails on Jenkins!

Output from the log:

[C:\jenkins\workspace\dockerfilecd4c215a] Running shell script
+ docker build -t cbe5e0bb1fa45f7ec37a2b15566f84aa9bd08f5d -f Dockerfile .
Sending build context to Docker daemon  337.4kB

Step 1/2 : FROM python:3.7-windowsservercore
 ---> 340689b75c39
Step 2/2 : RUN python -m pip install --upgrade pip
 ---> Using cache
 ---> a93f446a877f
Successfully built a93f446a877f
Successfully tagged cbe5e0bb1fa45f7ec37a2b15566f84aa9bd08f5d:latest
[C:\jenkins\workspace\dockerfilecd4c215a] Running shell script
+ docker inspect -f . cbe5e0bb1fa45f7ec37a2b15566f84aa9bd08f5d
.
Cannot run program "id": CreateProcess error=2, The system cannot find the file specified

回答1:


The issue is, that windows is not supported at the moment. It is calling the linux "id" command to get the current user id.

There is an open Pull Request and JIRA Ticket at Jenkins to support Windows docker pipeline:

  • https://issues.jenkins-ci.org/browse/JENKINS-36776
  • https://github.com/jenkinsci/docker-workflow-plugin/pull/148


来源:https://stackoverflow.com/questions/51537015/using-docker-for-windows-in-jenkins-declarative-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!