• Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • docker-workflow-plugin
    • None
    • Linux

      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".

          [JENKINS-41051] withRegistry is not doing a "docker login"

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

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

          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!

          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!

          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")
          }
          

          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" ) }

          Jesse Glick added a comment -

          Already done.

          Jesse Glick added a comment - Already done.

          vireshdoshi thanks, it work for me!

          Minh Thong Phan added a comment - vireshdoshi thanks, it work for me!

            magnayn magnayn
            dkarr David Karr
            Votes:
            8 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: