jenkinsci / jenkinsci/docker-workflow-plugin
[JENKINS-69444] Docker plugin fails to authenticate
- Dominant language
- Java
- Stars
- 527
- Forks
- 422
- Avg merge
- 10m
- Merged PRs (30d)
- 1
Description
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
---
Originally reported by derknerd, imported from: Docker plugin fails to authenticate
Raw content of original issue
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
Contributor guide
Assessment
This issue has not been assessed yet.