在Jenkins声明式管道中为Windows使用Docker [英] Using Docker for Windows in Jenkins Declarative Pipeline

查看:131
本文介绍了在Jenkins声明式管道中为Windows使用Docker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

设置::Jenkins master通过Docker在Linux 16.04上运行. Jenkins构建代理是

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

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

Docker 18.x在尝试使用Windows容器时让我头疼,所以我回滚到17.x.尝试与Jenkins一起运行时,我仍然遇到一些问题,并且nohup不在路上,但已通过其他参考).我怀疑我当前的问题可能与之有关.

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.

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

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

/Jenkinsfile

/Jenkinsfile

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

/Dockerfile

/Dockerfile

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

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

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

日志输出:

[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

推荐答案

问题是,当前不支持Windows.它正在调用linux"id"命令来获取当前的用户ID.

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

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

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

这篇关于在Jenkins声明式管道中为Windows使用Docker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆