docker container作为jenkins的构建奴隶

时间:2017-12-11 17:27:30

标签: docker jenkins jenkins-slave

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

  • Ubuntu 17.10
  • Jenkins ver。 2.73.3
  • Docker版本17.09.0-ce。

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

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

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

现在问题是我从Jenkins那里找到一份工作。它给出了一条错误消息 (pending-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用户构建容器。我需要在那里添加其他东西吗?

2 个答案:

答案 0 :(得分: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 :(得分:-1)

检查您的码头模板配置并选择" Never pool" for" pool strategy"。