Answer a question

With the below declarative pipeline code i am trying to pull an public image from dockerhub in jenkins however it fails with below error.

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

Jenkins console output:-

[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

Even pulling public images from dockerhub required authentication in jenkins? As i have already private registry(nexus) configured in jenkins in Declarative Pipeline (Docker) section, along with that i would want to pull public images from dockerhub.

Answers

From the exchange that we have on the comments from your initial question, we can get that your docker configuration on the "declarative pipeline" plugin is pointing out to a pull-through cache configuration rather than the public docker registry and you can see some info about that here https://docs.docker.com/registry/recipes/mirror/.

If you want to use the one configured on the plugin you should be able to configure credentials to access that repository and then select those credentials to be used with this private repository, and giving context for ppl coming to have a look at this problem, the plugin that you mentioned on your command has the following configuration: enter image description here

on Registry credentials do you have something selected? In my case I use artifactory repository but not configuring it with this plugin but with credentials configured on Jenkins and calling the full repository URL when declaring the agent on my pipelines.

Maybe you can avoid using the pipeline configured on the pipeline stating the full docker URL for downloading ubuntu instead of only the container+version like:

agent {
    docker {
        image 'registry.hub.docker.com/library/ubuntu:latest'
        label "jenkins-slave-01"
        }
}
Logo

CI/CD社区为您提供最前沿的新闻资讯和知识内容

更多推荐