0

使用下面的声明性管道代码,我试图从 jenkins 的 dockerhub 中提取公共图像,但是它失败并出现以下错误。

pipeline {  
    agent {
        docker {
            image 'ubuntu:latest'
            label "jenkins-slave-01"
            }
    }
    stages {    
        stage('Build') {    
            steps { 
                sh 'cat /etc/lsb-release'
            }   
        }   
        stage('Deploy') {   
            steps { 
                sh 'cat /etc/lsb-release'
            }   
        }           
    }   
}

詹金斯控制台输出: -

[Pipeline] withDockerRegistry
Using the existing docker config file.Removing blacklisted property: auths$ docker login -u test -p ******** https://index.docker.io/v1/
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password
[Pipeline] // withDockerRegistry
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: docker login failed
Finished: FAILURE

即使从 dockerhub 中提取公共图像也需要在 jenkins 中进行身份验证?由于我已经在 jenkins 中配置了私有注册表(nexus)Declarative Pipeline (Docker),因此我想从 dockerhub 中提取公共图像。

4

1 回答 1

1

从我们对您最初问题的评论的交流中,我们可以了解到您在“声明性管道”插件上的 docker 配置指向的是一个直通缓存配置,而不是公共 docker 注册表,您可以看到一些信息关于这里https://docs.docker.com/registry/recipes/mirror/

如果您想使用插件上配置的那个,您应该能够配置凭据以访问该存储库,然后选择要与此私有存储库一起使用的那些凭据,并为 ppl 来查看此问题提供上下文,您在命令中提到的插件具有以下配置: 在此处输入图像描述

在注册表凭据上,您是否选择了某些内容?在我的情况下,我使用工件存储库,但没有使用此插件配置它,而是使用在 Jenkins 上配置的凭据并在我的管道上声明代理时调用完整的存储库 URL。

也许您可以避免使用管道上配置的管道,说明用于下载 ubuntu 的完整 docker URL,而不仅仅是容器+版本,例如:

agent {
    docker {
        image 'registry.hub.docker.com/library/ubuntu:latest'
        label "jenkins-slave-01"
        }
}
于 2021-04-28T07:03:40.407 回答