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

Docker plugin fails to authenticate

XMLWordPrintable

      I am currently run a Jenkins server in Kubernetes. When I want to authenticate with docker the login won't work, neither dockerhub nor my own quay server.

      Here is a sample Jenkinsfile that doesn't work.

      // Uses Declarative syntax to run commands inside a container.
      pipeline {
          triggers {
              pollSCM("*/5 * * * *")
          }
          agent {
              kubernetes {
                  yaml '''
      apiVersion: v1
      kind: Pod
      spec:
        volumes:
          - name: docker-sock
            hostPath:
              path: /var/run/docker.sock
        containers:
        - name: docker
          image: docker:latest
          command:
          - cat
          tty: true
          volumeMounts:
          - mountPath: /var/run/docker.sock
            name: docker-sock
      '''
                  defaultContainer 'golang'
              }
          }
          stages {
              stage('Push') {
                  steps {
                      container('docker') {
                          sh "docker build -t quay.imanuel.dev/jenny-jinya/shopware-tools:$BUILD_NUMBER ."
                          withDockerRegistry(credentialsId: 'quay.imanuel.dev', url: 'https://quay.imanuel.dev') {
                              sh "docker push quay.imanuel.dev/jenny-jinya/shopware-tools:$BUILD_NUMBER"
                          }
                      }
                  }
              }
          }
      }
      

      After changing it to this, the login and push work as expected

      // Uses Declarative syntax to run commands inside a container.
      pipeline {
          triggers {
              pollSCM("*/5 * * * *")
          }
          agent {
              kubernetes {
                  yaml '''
      apiVersion: v1
      kind: Pod
      spec:
        volumes:
          - name: docker-sock
            hostPath:
              path: /var/run/docker.sock
        containers:
        - name: docker
          image: docker:latest
          command:
          - cat
          tty: true
          volumeMounts:
          - mountPath: /var/run/docker.sock
            name: docker-sock
      '''
                  defaultContainer 'golang'
              }
          }
          stages {
              stage('Push') {
                  steps {
                      container('docker') {
                          sh "docker build -t quay.imanuel.dev/jenny-jinya/shopware-tools:$BUILD_NUMBER ."
                          withCredentials([usernamePassword(credentialsId: 'quay.imanuel.dev', passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
                              sh "echo ${DOCKER_PASS} | docker login -u ${DOCKER_USER} --password-stdin quay.imanuel.dev"
                          }
                          sh "docker push quay.imanuel.dev/jenny-jinya/shopware-tools:$BUILD_NUMBER"
                      }
                  }
              }
          }
      } 

      The versions are as follows:

      Jenkins: Jenkins 2.365
      docker-workflow: 521.v1a_a_dd2073b_2e

            Unassigned Unassigned
            derknerd Imanuel Ulbricht
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: