Jenkins 脚本化管道作业因 docker 登录而失败

问题描述 投票:0回答:2
Jenkins Version - 2.164.1
Jenkins Docker Plugin Version – 1.1.6
Docker Version - 18.09.3, build 774a1f4

问题:-

我的 Jenkins 脚本化管道部分中有以下代码。我已经添加了我的私有 Docker 注册表 URL 和在管理 Jenkins --> 配置系统下添加的凭据。但是管道作业无法进行 docker 登录。

Jenkins 错误 -

ERROR: docker login failed

代码:-

stage('Build') { 
  withDockerRegistry(credentialsId: 'docker-reg-credentails', url: 'http://registryhub:8081/nexus/') {
    image = docker.image('registryhub:8085/ubuntu-16:1')
    image.pull()
    docker.image('registryhub:8085/ubuntu-16:1').inside {   
      sh 'cat /etc/issue'
    }
  }
}
docker jenkins jenkins-pipeline docker-registry
2个回答
1
投票

在 Stage 内,执行如下操作:

    script
        {
        def server = Nexus.server 'docker-reg-credentails'
        def buildRegistry = [ url: 'http://registryhub:8081/nexus/', credentialsId: 'docker-reg-credentails' ]
        def rtDocker = Nexus.docker server: server
            withDockerRegistry(registry: buildRegistry ) 
            {
                sh 'docker pull hello-world' 
                sh 'docker tag hello-world:latest hello-world:latest2' 
                rtDocker.addProperty("status", "stable") 
                def buildInfo = rtDocker.push 'hello-world:latest', 'docker-local'
                // Step 4: Publish the build-info to Nexus: server.publishBuildInfo buildInfo

                server.publishBuildInfo buildInfo
            }
            }

0
投票

如果您尝试在

sh
中显式运行docker登录,您可以获得有关失败原因的更多信息。最可能的原因是连接到 docker 守护程序时访问被拒绝。所以你需要将 Jenkins 帐户添加到 docker 组,例如

sudo usermod -a -G docker jenkins
© www.soinside.com 2019 - 2024. All rights reserved.