Jenkins & GitLab & Docker 集成失败

Jenkins & GitLab & Docker integration fails

詹金斯

在 Jenkins 中,我决定使用远程 docker 功能。 所以我在 linux 服务器上安装了 docker.io 并使用了这个管道。

node {
    stage('Example') {
        docker.withServer('tcp://docker.example.org:2375') {
            docker.image('stefanscherer/node-windows:10').inside {
                sh 'node --version'
            }
        }
    }
}

但这会失败,并显示有关卷配置的错误消息。

java.io.IOException: Failed to run image 'stefanscherer/node-windows:10'. Error: docker: Error response from daemon: invalid volume specification: '/var/lib/jenkins/workspace/Docker Test:/var/lib/jenkins/workspace/Docker Test:rw,z'.
See 'docker run --help'.
    at org.jenkinsci.plugins.docker.workflow.client.DockerClient.run(DockerClient.java:133)

也许问题是我尝试将 linux Jenkins 与 docker Windows 结合起来? 但我读到的是 experimental 选项,它应该允许使用 Linux 容器。

GitLab

通过本指南安装的 GitLab-Runner。 https://docs.gitlab.com/runner/install/windows.html 然后我连接它并选择 docker 作为执行者。

当我从 daemon.json 中删除 hosts 时,我收到此错误消息。

ERROR: Preparation failed: Error response from daemon: client version 1.18 is too old. Minimum supported API version is 1.24, please upgrade your client to a newer version (executor_docker.go:1161:0s)

如何获得支持较新API的版本? 我读了一篇文章,说 GitLab 正在等待 LTS EOL(生命周期结束)。我想 CentOS 或其他东西。

当我在 daemon.json 中设置 hosts 时,我收到此错误消息。

ERROR: Preparation failed: error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.18/info: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running. (executor_docker.go:1161:0s)

那是因为 runner 找不到 Docker,因为 Docker 只在 TCP 端口上侦听。 我尝试将 //./pipe/docker_engine 添加到 daemon.jsonhosts,但没有成功。 docker 服务立即崩溃。

Docker

Windows 服务器 2016

daemon.json

{
    "hosts": ["tcp://0.0.0.0:2375"],
    "experimental": true
}

目标

我的目标是在 (windows) Docker.

上从 (linux) Jenkins 和 (linux) GitLab 构建我的工作

问题

Jenkins 通常无法正常工作,可能是因为某些设置或者因为它试图挂载 windows 路径?

GitLab 期待 docker 不提供的旧 API。

目标

您的方向是正确的,分发您的 CI 管道可以轻松扩展,容器是实现此目的的理想解决方案。

詹金斯

Docker Pipeline Jenkins documentation中解释为:

For inside() to work, the Docker server and the Jenkins agent must use the same filesystem, so that the workspace can be mounted.

所以请尝试使用其他命令(例如 withRun),看看,无论如何,我在这里遗漏了一些凭据。您还可以为 Docker 配置一个新的 Jenkins 节点,在那里您可以指定执行作业的路径。

GitLab

Windows 上的 GitLab runner 问题计划包含在 11.8 版本(2019 年 2 月)中,如 here.

所述

结论

如果您不能等到新的 GitLab 发布,我会进行 Linux 安装,并且我会为 docker 配置添加一个新的 Jenkins 节点,正如所描述的那样 here .