【问题标题】:docker container as build slave for jenkinsdocker 容器作为詹金斯的构建奴隶
【发布时间】:2017-12-11 17:27:30
【问题描述】:

我已经在同一台机器 Ubuntu 上安装了 Jenkins 和 docker。

  • Ubuntu 17.10
  • 詹金斯版本。 2.73.3
  • Docker 版本 17.09.0-ce。

我正在尝试将 jenkin docker 容器设置为从属设备以运行我的自动化测试套件。

我能够正确地在 Jenkins 中设置 docker 插件以启动 docker 容器,并添加了一个 docker 模板,其中包含我为设置 docker 环境而创建的图像。

该映像是在 Ubuntu 中托管的 docker 上构建的。

现在问题是当我从 Jenkins 运行工作时。它给出了一条错误消息 (待定——Jenkins 没有标签 docker-slave)

Jenkins pending image

当我在 Ubuntu 机器上检查 Jenkins 日志时,我看到以下错误消息

com.github.dockerjava.api.exception.NotFoundException: {"message":"pull access 
denied, "message":may require 'docker login'"}

在 ubuntu 机器上,我已经完成了 docker login。

我试图从中构建容器的图像在 ubuntu 本地,没有推送到任何存储库,所以为什么要尝试提取图像。

另外,我需要解决的权限问题是什么。从詹金斯构建工作时,詹金斯用户构建容器。我需要在那里添加其他东西吗?

【问题讨论】:

    标签: docker jenkins jenkins-slave


    【解决方案1】:

    在您的 Jenkinsfile 中,您可以使用带有 credentials plugin 的凭据:

        // Login to registry
        withCredentials([usernamePassword(credentialsId: 'YOUR_ID_AD_DEFINED_IN_JENKINS', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
            sh "docker login --username=$USER --password=$PASS your.registry.here.com"
        }
    
        // Build with correct pom version
        sh "docker build -t your.registry.here.com/your_image_here/your_image_name:${POM_VERSION} ."
    
        // Push
        sh "docker push your.registry.here.com/your_image_here/your_image_name:${POM_VERSION}"
    
        //pull
        sh "docker pull your.registry.here.com/your_image_here/your_image_name:${POM_VERSION}"
    

    ${POM_VERSION} 只是我自己的代码的一个翻版,当然可以是你喜欢的任何版本

    您还需要在 Jenkins 服务器中定义凭据。可以在这里找到描述Working with jenkins credentials

    【讨论】:

    • 感谢@Ivonet 的回复。您指的是哪个 Jenkinsfile。我的配置中没有任何特定的 jenkins 文件。
    • 啊,这是我的假设,抱歉。然后我会提倡开始使用一个 :-) 这样你就可以在你的项目中配置 Jenkins。
    【解决方案2】:

    检查您的 docker 模板配置并为“池策略”选择“从不池”。

    【讨论】:

      猜你喜欢
      • 2018-11-11
      • 2015-07-25
      • 2011-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多