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

withDockerRegistry fails to authenticate with DockerHub

      When using either docker.withRegistry('', 'dockerhub') or withDockerRegistry(registry: [credentialsId: 'dockerhub']), a call to mycont.push() fails to authenticate with DockerHub:

        withDockerRegistry(registry: [credentialsId: 'dockerhub']) {
          cont.push()
          cont.push('latest')
        }
      

      leads to:

      Proceeding
      [Pipeline] withDockerRegistry
      [Pipeline] {
      [Pipeline] sh
      [test] Running shell script
      + docker tag --force=true camptocamp/jenkins-test camptocamp/jenkins-test:latest
      unknown flag: --force
      See 'docker tag --help'.
      + docker tag camptocamp/jenkins-test camptocamp/jenkins-test:latest
      [Pipeline] sh
      [test] Running shell script
      + docker push camptocamp/jenkins-test:latest
      The push refers to a repository [docker.io/camptocamp/jenkins-test]
      749689370cd8: Preparing
      unauthorized: authentication required
      [Pipeline] }
      [Pipeline] // withDockerRegistry
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      

      I have the credentials set up properly in Jenkins, as shown in the attached screenshot, but Jenkins Credentials Manager says `This credential has not been recorded as used anywhere.`

          [JENKINS-38018] withDockerRegistry fails to authenticate with DockerHub

          Raphaël PINSON created issue -
          Raphaël PINSON made changes -
          Description Original: When using either `docker.withRegistry('', 'dockerhub')` or `withDockerRegistry(registry: [credentialsId: 'dockerhub'])`, a call to `mycont.push()` fails to authenticate with DockerHub:

          {code:groovy}
            withDockerRegistry(registry: [credentialsId: 'dockerhub']) {
              cont.push()
              cont.push('latest')
            }
          {code}


          leads to:

          {code:logs}
          Proceeding
          [Pipeline] withDockerRegistry
          [Pipeline] {
          [Pipeline] sh
          [test] Running shell script
          + docker tag --force=true camptocamp/jenkins-test camptocamp/jenkins-test:latest
          unknown flag: --force
          See 'docker tag --help'.
          + docker tag camptocamp/jenkins-test camptocamp/jenkins-test:latest
          [Pipeline] sh
          [test] Running shell script
          + docker push camptocamp/jenkins-test:latest
          The push refers to a repository [docker.io/camptocamp/jenkins-test]
          749689370cd8: Preparing
          unauthorized: authentication required
          [Pipeline] }
          [Pipeline] // withDockerRegistry
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {code}

          I have the credentials set up properly in Jenkins, as shown in the attached screenshot, but Jenkins Credentials Manager says `This credential has not been recorded as used anywhere.`
          New: When using either {{docker.withRegistry('', 'dockerhub')}} or {{withDockerRegistry(registry: [credentialsId: 'dockerhub'])}}, a call to {{mycont.push()}} fails to authenticate with DockerHub:

          {code:groovy}
            withDockerRegistry(registry: [credentialsId: 'dockerhub']) {
              cont.push()
              cont.push('latest')
            }
          {code}


          leads to:

          {code:logs}
          Proceeding
          [Pipeline] withDockerRegistry
          [Pipeline] {
          [Pipeline] sh
          [test] Running shell script
          + docker tag --force=true camptocamp/jenkins-test camptocamp/jenkins-test:latest
          unknown flag: --force
          See 'docker tag --help'.
          + docker tag camptocamp/jenkins-test camptocamp/jenkins-test:latest
          [Pipeline] sh
          [test] Running shell script
          + docker push camptocamp/jenkins-test:latest
          The push refers to a repository [docker.io/camptocamp/jenkins-test]
          749689370cd8: Preparing
          unauthorized: authentication required
          [Pipeline] }
          [Pipeline] // withDockerRegistry
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {code}

          I have the credentials set up properly in Jenkins, as shown in the attached screenshot, but Jenkins Credentials Manager says `This credential has not been recorded as used anywhere.`
          Raphaël PINSON made changes -
          Description Original: When using either {{docker.withRegistry('', 'dockerhub')}} or {{withDockerRegistry(registry: [credentialsId: 'dockerhub'])}}, a call to {{mycont.push()}} fails to authenticate with DockerHub:

          {code:groovy}
            withDockerRegistry(registry: [credentialsId: 'dockerhub']) {
              cont.push()
              cont.push('latest')
            }
          {code}


          leads to:

          {code:logs}
          Proceeding
          [Pipeline] withDockerRegistry
          [Pipeline] {
          [Pipeline] sh
          [test] Running shell script
          + docker tag --force=true camptocamp/jenkins-test camptocamp/jenkins-test:latest
          unknown flag: --force
          See 'docker tag --help'.
          + docker tag camptocamp/jenkins-test camptocamp/jenkins-test:latest
          [Pipeline] sh
          [test] Running shell script
          + docker push camptocamp/jenkins-test:latest
          The push refers to a repository [docker.io/camptocamp/jenkins-test]
          749689370cd8: Preparing
          unauthorized: authentication required
          [Pipeline] }
          [Pipeline] // withDockerRegistry
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {code}

          I have the credentials set up properly in Jenkins, as shown in the attached screenshot, but Jenkins Credentials Manager says `This credential has not been recorded as used anywhere.`
          New: When using either {{docker.withRegistry('', 'dockerhub')}} or {{withDockerRegistry(registry: [credentialsId: 'dockerhub'])}}, a call to {{mycont.push()}} fails to authenticate with DockerHub:

          {code:java}
            withDockerRegistry(registry: [credentialsId: 'dockerhub']) {
              cont.push()
              cont.push('latest')
            }
          {code}


          leads to:

          {code:logs}
          Proceeding
          [Pipeline] withDockerRegistry
          [Pipeline] {
          [Pipeline] sh
          [test] Running shell script
          + docker tag --force=true camptocamp/jenkins-test camptocamp/jenkins-test:latest
          unknown flag: --force
          See 'docker tag --help'.
          + docker tag camptocamp/jenkins-test camptocamp/jenkins-test:latest
          [Pipeline] sh
          [test] Running shell script
          + docker push camptocamp/jenkins-test:latest
          The push refers to a repository [docker.io/camptocamp/jenkins-test]
          749689370cd8: Preparing
          unauthorized: authentication required
          [Pipeline] }
          [Pipeline] // withDockerRegistry
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {code}

          I have the credentials set up properly in Jenkins, as shown in the attached screenshot, but Jenkins Credentials Manager says `This credential has not been recorded as used anywhere.`
          Raphaël PINSON made changes -
          Description Original: When using either {{docker.withRegistry('', 'dockerhub')}} or {{withDockerRegistry(registry: [credentialsId: 'dockerhub'])}}, a call to {{mycont.push()}} fails to authenticate with DockerHub:

          {code:java}
            withDockerRegistry(registry: [credentialsId: 'dockerhub']) {
              cont.push()
              cont.push('latest')
            }
          {code}


          leads to:

          {code:logs}
          Proceeding
          [Pipeline] withDockerRegistry
          [Pipeline] {
          [Pipeline] sh
          [test] Running shell script
          + docker tag --force=true camptocamp/jenkins-test camptocamp/jenkins-test:latest
          unknown flag: --force
          See 'docker tag --help'.
          + docker tag camptocamp/jenkins-test camptocamp/jenkins-test:latest
          [Pipeline] sh
          [test] Running shell script
          + docker push camptocamp/jenkins-test:latest
          The push refers to a repository [docker.io/camptocamp/jenkins-test]
          749689370cd8: Preparing
          unauthorized: authentication required
          [Pipeline] }
          [Pipeline] // withDockerRegistry
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {code}

          I have the credentials set up properly in Jenkins, as shown in the attached screenshot, but Jenkins Credentials Manager says `This credential has not been recorded as used anywhere.`
          New: When using either {{docker.withRegistry('', 'dockerhub')}} or {{withDockerRegistry(registry: [credentialsId: 'dockerhub'])}}, a call to {{mycont.push()}} fails to authenticate with DockerHub:

          {code:java}
            withDockerRegistry(registry: [credentialsId: 'dockerhub']) {
              cont.push()
              cont.push('latest')
            }
          {code}


          leads to:

          {code:none}
          Proceeding
          [Pipeline] withDockerRegistry
          [Pipeline] {
          [Pipeline] sh
          [test] Running shell script
          + docker tag --force=true camptocamp/jenkins-test camptocamp/jenkins-test:latest
          unknown flag: --force
          See 'docker tag --help'.
          + docker tag camptocamp/jenkins-test camptocamp/jenkins-test:latest
          [Pipeline] sh
          [test] Running shell script
          + docker push camptocamp/jenkins-test:latest
          The push refers to a repository [docker.io/camptocamp/jenkins-test]
          749689370cd8: Preparing
          unauthorized: authentication required
          [Pipeline] }
          [Pipeline] // withDockerRegistry
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          {code}

          I have the credentials set up properly in Jenkins, as shown in the attached screenshot, but Jenkins Credentials Manager says `This credential has not been recorded as used anywhere.`

          Nevermind, the user I was using didn't have rights to push to that repository… Sorry for the noise, everything works.

          Raphaël PINSON added a comment - Nevermind, the user I was using didn't have rights to push to that repository… Sorry for the noise, everything works.
          Raphaël PINSON made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]

          Actually, it still doesn't work. It worked because I had used the following code at some point:

              withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'dockerhub',
                  usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
                sh 'docker login -u "$USERNAME" -p "$PASSWORD"'
                cont.push()
              }
          

          and it didn't remove the credentials, so switching to `withDockerRegistry()` after that used the credentials still stored in `~/.docker`.

          I've just experienced that `withDockerRegistry()` on clean slaves doesn't work, and had to revert to using `withCredentials()`.

          Raphaël PINSON added a comment - Actually, it still doesn't work. It worked because I had used the following code at some point: withCredentials([[$class: 'UsernamePasswordMultiBinding' , credentialsId: 'dockerhub' , usernameVariable: 'USERNAME' , passwordVariable: 'PASSWORD' ]]) { sh 'docker login -u "$USERNAME" -p "$PASSWORD" ' cont.push() } and it didn't remove the credentials, so switching to `withDockerRegistry()` after that used the credentials still stored in `~/.docker`. I've just experienced that `withDockerRegistry()` on clean slaves doesn't work, and had to revert to using `withCredentials()`.
          Raphaël PINSON made changes -
          Resolution Original: Fixed [ 1 ]
          Status Original: Resolved [ 5 ] New: Reopened [ 4 ]

          +1, I have the same problem

          Nathan Hüsken added a comment - +1, I have the same problem

          Jesse Glick added a comment - - edited

          withRegistry continues to work in the stock demo (using registry:0.9.1) but perhaps DockerHub changed their authentication mechanism? Need to check if this is reproducible from scratch.

          Jesse Glick added a comment - - edited withRegistry continues to work in the stock demo (using registry:0.9.1 ) but perhaps DockerHub changed their authentication mechanism? Need to check if this is reproducible from scratch.

            jglick Jesse Glick
            raphink Raphaël PINSON
            Votes:
            16 Vote for this issue
            Watchers:
            35 Start watching this issue

              Created:
              Updated:
              Resolved: