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

Docker registry credentials doesn't apply on multibranch pipeline

      I created a Multibranch pipeline job and configure docker registry credentials in the Pipeline Model Definition section (see attachment)

      Jenkins file below:

       

      pipeline {
        agent any
          
        stages {
          stage('Build') {
            steps {
              script {
                def image = docker.build "***.com/docker-build-demo:${env.BUILD_TAG}"
                image.push()
                image.push('latest')
              }
            }
          }
        }
      }

      And pipeline failed on docker push step:

       

       

      + docker push ***.com/docker-build-demo:jenkins-docker-build-demo-master-4
      The push refers to repository [***.com/docker-build-demo]
      ebf12965380b: Preparing
      denied: requested access to the resource is denied
      script returned exit code 1

       

      I can do workaround like this to make the pipeline success but that makes the Jenkinsfile bind to specific jenkins configuration and cannot be run everywhere:

       

       

      pipeline {
        agent any
          
        stages {
          stage('Build') {
            steps {
              script {
                docker.withRegistry('https://***.com', 'credential-id') {
                  def image = docker.build "***.com/docker-build-demo:${env.BUILD_TAG}"
                  image.push()
                  image.push('latest')
                }
              }
            }
          }
        }
      }

       

          [JENKINS-54901] Docker registry credentials doesn't apply on multibranch pipeline

          Daniel Qian created issue -
          Daniel Qian made changes -
          Attachment New: Pipeline Model Definition.png [ 45300 ]
          Daniel Qian made changes -
          Description Original: I created a Multibranch pipeline job and configure docker registry credentials in the *Pipeline Model Definition* section (see attachment)

          Jenkins file below:

           
          {code:java}
          pipeline {
            agent any
              
            stages {
              stage('Build') {
                steps {
                  script {
                    def image = docker.build "***.com/docker-build-demo:${env.BUILD_TAG}"
                    image.push()
                    image.push('latest')
                  }
                }
              }
            }
          }{code}
          And pipeline failed on docker push step:

           

           
          {code:java}
          + docker push ***.com/docker-build-demo:jenkins-docker-build-demo-master-4
          The push refers to repository [***.com/docker-build-demo]
          ebf12965380b: Preparing
          denied: requested access to the resource is denied
          script returned exit code 1{code}
           

          I can do workaround like this to make the pipeline success but that makes the Jenkinsfile bind to specific jenkins configuration and cannot be run everywhere:

           

           
          {code:java}
          pipeline {
            agent any
              
            stages {
              stage('Build') {
                steps {
                  script {
                    docker.withRegistry('https://xxx.com', 'credential-id') {
                      def image = docker.build "harbor.supwisdom.com/institute/docker-build-demo:${env.BUILD_TAG}"
                      image.push()
                      image.push('latest')
                    }
                  }
                }
              }
            }
          }{code}
           
          New: I created a Multibranch pipeline job and configure docker registry credentials in the *Pipeline Model Definition* section (see attachment)

          Jenkins file below:

           
          {code:java}
          pipeline {
            agent any
              
            stages {
              stage('Build') {
                steps {
                  script {
                    def image = docker.build "***.com/docker-build-demo:${env.BUILD_TAG}"
                    image.push()
                    image.push('latest')
                  }
                }
              }
            }
          }{code}
          And pipeline failed on docker push step:

           

           
          {code:java}
          + docker push ***.com/docker-build-demo:jenkins-docker-build-demo-master-4
          The push refers to repository [***.com/docker-build-demo]
          ebf12965380b: Preparing
          denied: requested access to the resource is denied
          script returned exit code 1{code}
           

          I can do workaround like this to make the pipeline success but that makes the Jenkinsfile bind to specific jenkins configuration and cannot be run everywhere:

           

           
          {code:java}
          pipeline {
            agent any
              
            stages {
              stage('Build') {
                steps {
                  script {
                    docker.withRegistry('https://xxx.com', 'credential-id') {
                      def image = docker.build "***.com/docker-build-demo:${env.BUILD_TAG}"
                      image.push()
                      image.push('latest')
                    }
                  }
                }
              }
            }
          }{code}
           
          Daniel Qian made changes -
          Description Original: I created a Multibranch pipeline job and configure docker registry credentials in the *Pipeline Model Definition* section (see attachment)

          Jenkins file below:

           
          {code:java}
          pipeline {
            agent any
              
            stages {
              stage('Build') {
                steps {
                  script {
                    def image = docker.build "***.com/docker-build-demo:${env.BUILD_TAG}"
                    image.push()
                    image.push('latest')
                  }
                }
              }
            }
          }{code}
          And pipeline failed on docker push step:

           

           
          {code:java}
          + docker push ***.com/docker-build-demo:jenkins-docker-build-demo-master-4
          The push refers to repository [***.com/docker-build-demo]
          ebf12965380b: Preparing
          denied: requested access to the resource is denied
          script returned exit code 1{code}
           

          I can do workaround like this to make the pipeline success but that makes the Jenkinsfile bind to specific jenkins configuration and cannot be run everywhere:

           

           
          {code:java}
          pipeline {
            agent any
              
            stages {
              stage('Build') {
                steps {
                  script {
                    docker.withRegistry('https://xxx.com', 'credential-id') {
                      def image = docker.build "***.com/docker-build-demo:${env.BUILD_TAG}"
                      image.push()
                      image.push('latest')
                    }
                  }
                }
              }
            }
          }{code}
           
          New: I created a Multibranch pipeline job and configure docker registry credentials in the *Pipeline Model Definition* section (see attachment)

          Jenkins file below:

           
          {code:java}
          pipeline {
            agent any
              
            stages {
              stage('Build') {
                steps {
                  script {
                    def image = docker.build "***.com/docker-build-demo:${env.BUILD_TAG}"
                    image.push()
                    image.push('latest')
                  }
                }
              }
            }
          }{code}
          And pipeline failed on docker push step:

           

           
          {code:java}
          + docker push ***.com/docker-build-demo:jenkins-docker-build-demo-master-4
          The push refers to repository [***.com/docker-build-demo]
          ebf12965380b: Preparing
          denied: requested access to the resource is denied
          script returned exit code 1{code}
           

          I can do workaround like this to make the pipeline success but that makes the Jenkinsfile bind to specific jenkins configuration and cannot be run everywhere:

           

           
          {code:java}
          pipeline {
            agent any
              
            stages {
              stage('Build') {
                steps {
                  script {
                    docker.withRegistry('https://***.com', 'credential-id') {
                      def image = docker.build "***.com/docker-build-demo:${env.BUILD_TAG}"
                      image.push()
                      image.push('latest')
                    }
                  }
                }
              }
            }
          }{code}
           
          Matthew DeTullio made changes -
          Component/s New: pipeline [ 21692 ]
          Component/s Original: multi-branch-project-plugin (not Pipeline) [ 21127 ]
          Matthew DeTullio made changes -
          Assignee Original: Matthew DeTullio [ mjdetullio ] New: Andrew Bayer [ abayer ]
          Andrew Bayer made changes -
          Assignee Original: Andrew Bayer [ abayer ]

            Unassigned Unassigned
            chanjarster Daniel Qian
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: