在Jenkins声明式管道中为Windows使用Docker

时间:2018-07-26 10:47:38

标签: docker jenkins dockerfile jenkins-declarative-pipeline

我正在通过Dockerfile使用Jenkins声明性管道和Docker-for-Windows代理程序来设置CI工作流。

注意:不幸的是,由于我需要运行Windows二进制文件,因此当前不是使用基于Linux的docker守护程序的解决方案。

设置:Jenkins主服务器通过Docker在Linux 16.04上运行。 Jenkins构建代理是

  • Windows 10企业版1709(16299.551)
  • 适用于Windows的Docker 17.12.0-ce

Docker 18.x在尝试使用Windows容器时让我头疼,所以我回滚到17.x。尝试与Jenkins一起运行时,我仍然遇到一些问题,并且nohup不在路上,但是adding Git binaries to Windows search pathanother reference)解决了这个问题。我怀疑我当前的问题可能与之有关。

代码:我正在尝试初始化Jenkinsfile并在其中运行简单的hello-world-printout。

/ 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

基本上,这应该是干净的图像,只打印“ Hello,World!”。 但是在詹金斯身上失败了!

日志输出:

[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 个答案:

答案 0 :(得分:3)

问题是,当前不支持Windows。它正在调用linux“ id”命令以获取当前用户ID。

Jenkins提供了一个开放的Pull Request和JIRA Ticket,以支持Windows docker管道: