docker container作为jenkins的构建奴隶

问题描述 投票:0回答:2

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

  • Ubuntu 17.10
  • 詹金斯诉。 2.73.3
  • Docker版本17.09.0-这个。

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

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

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

现在问题出在我从詹金斯那里找工作的时候。它给出了一条错误消息(挂起 - 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登录。

我试图建立容器的图像是在ubuntu本地,而不是推送到任何存储库,所以为什么要尝试拉取图像。

另外,我需要解决的权限问题是什么。当建立一个工作,从jenkins,它的jenkins用户构建容器。我需要在那里添加其他东西吗?

docker jenkins jenkins-slave
2个回答
0
投票

在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


-1
投票

检查您的docker模板配置,并为“pool strategy”选择“Never pool”。

© www.soinside.com 2019 - 2024. All rights reserved.