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

Problem:-

I have below code in my Jenkins scripted pipeline section. I have added my private Docker registry URL and Credentials added under Manage Jenkins --> Configure System. But pipeline Job is failing for docker login.

Error form Jenkins - ERROR: docker login failed

Code:-

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'
    }
  }
}
4
  • 1
    Can you login with those credentials manually as the Jenkins user from the build node? Commented Apr 3, 2019 at 12:52
  • 1
    Yes able to login with my private registry credentials, Also able to pull and push the images through terminal. Problem is with through Jenkins. Commented Apr 3, 2019 at 13:08
  • @Kishore Does it always fail or is it more of sporadic failure ? Commented Feb 9, 2021 at 16:00
  • @MuhammadFaizan-Ul-Haq, It was resolved after docker service restart. Commented Feb 10, 2021 at 3:06

2 Answers 2

1

Inside Stage, do something like below:

    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

If you try to run docker login explicitly in sh, you can get more information about the cause of failure. Most probable cause would be access denied on connection to docker daemon. So you need add Jenkins account to docker group, e.g.

sudo usermod -a -G docker jenkins

Not the answer you're looking for? Browse other questions tagged or ask your own question.