Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-41051

withRegistry is not doing a "docker login"

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I have a block in my pipeline script like the following:

      		docker.withRegistry("http://ourhost:5100", params.JP_DockerMechIdCredential) {
      			def	image = docker.build("com.att.sharedservices/tomee-uslmonitor")
      			image.push 'latest'
      		}
      

      Before this block of code, I extracted the username and password from the credential, and they are correct.

      In the log, I watched it build the image, tag it, but then when it tried to push it, it failed to authenticate. I didn't see a "docker login" command line in the log.

      I then tried to manually run the docker commands from the shell, on the same box the job is running on, starting with "docker login". That entire process worked.

      I then reran my job, and it also worked.

      I then moved my "~/.docker/config.json" file out of the way and reran my job, and it failed to authenticate again. It's just not attempting "docker login".

        Attachments

          Issue Links

            Activity

            Hide
            dkarr David Karr added a comment -

            Note that I was able to implement a workaround, with a modified block like this:

            		withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: params.JP_DockerMechIdCredential, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
            			usr = USERNAME
            			pswd = PASSWORD
            		}
            		docker.withRegistry("http://ourhost:5100", params.JP_DockerMechIdCredential) {
            			sh "docker login -u ${usr} -p ${pswd} http://ourhost:5100"
            			def	image = docker.build("com.att.sharedservices/tomee-uslmonitor")
            			image.push 'latest'
            		}
            
            Show
            dkarr David Karr added a comment - Note that I was able to implement a workaround, with a modified block like this: withCredentials([[$class: 'UsernamePasswordMultiBinding' , credentialsId: params.JP_DockerMechIdCredential, usernameVariable: 'USERNAME' , passwordVariable: 'PASSWORD' ]]) { usr = USERNAME pswd = PASSWORD } docker.withRegistry( "http: //ourhost:5100" , params.JP_DockerMechIdCredential) { sh "docker login -u ${usr} -p ${pswd} http: //ourhost:5100" def image = docker.build( "com.att.sharedservices/tomee-uslmonitor" ) image.push 'latest' }
            Hide
            rgielen René Gielen added a comment -

            I can confirm the exact issue, as well as the workaround. The workaround, however, is really nasty and I doubt other users would will find this easily.

            A solution to this issue, having withRegistry work as one would expect, is highly welcome!

            Show
            rgielen René Gielen added a comment - I can confirm the exact issue, as well as the workaround. The workaround, however, is really nasty and I doubt other users would will find this easily. A solution to this issue, having withRegistry work as one would expect, is highly welcome!
            Hide
            vireshdoshi viresh doshi added a comment -

            I can also confirm that this worked!

            I ended up using the following workaround:

            // code placeholder
            stage('Push image') {
            /* Finally, we'll push the image with two tags:
            * First, the incremental build number from Jenkins
            * Second, the 'latest' tag. */
            withCredentials([usernamePassword( credentialsId: 'docker-hub-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
            
            docker.withRegistry('', 'docker-hub-credentials') {
            sh "docker login -u ${USERNAME} -p ${PASSWORD}"
            myImage.push("${env.BUILD_NUMBER}")
            myImage.push("latest")
            }
            
            Show
            vireshdoshi viresh doshi added a comment - I can also confirm that this worked! I ended up using the following workaround: // code placeholder stage( 'Push image' ) { /* Finally, we'll push the image with two tags: * First, the incremental build number from Jenkins * Second, the 'latest' tag. */ withCredentials([usernamePassword( credentialsId: 'docker-hub-credentials' , usernameVariable: 'USERNAME' , passwordVariable: 'PASSWORD' )]) { docker.withRegistry( '', ' docker-hub-credentials') { sh "docker login -u ${USERNAME} -p ${PASSWORD}" myImage.push( "${env.BUILD_NUMBER}" ) myImage.push( "latest" ) }
            Hide
            jglick Jesse Glick added a comment -

            Already done.

            Show
            jglick Jesse Glick added a comment - Already done.

              People

              • Assignee:
                magnayn magnayn
                Reporter:
                dkarr David Karr
              • Votes:
                8 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: