gpt4 book ai didi

docker - Jenkins 脚本化管道作业因 docker login 失败

转载 作者:行者123 更新时间:2023-12-03 21:41:50 25 4
gpt4 key购买 nike

Jenkins Version - 2.164.1
Jenkins Docker Plugin Version – 1.1.6
Docker Version - 18.09.3, build 774a1f4

问题:-

我的 Jenkins 脚本化管道部分中有以下代码。我已经在 Manage Jenkins --> Configure System 下添加了我的私有(private) Docker 注册表 URL 和凭据。但是管道作业因 docker 登录而失败。

Error form 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'
}
}
}

最佳答案

在 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
}
}

关于docker - Jenkins 脚本化管道作业因 docker login 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55488940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com