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

Docker registry credentials doesn't apply on multibranch pipeline

XMLWordPrintable

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

       

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

              Created:
              Updated: