I use Jenkins locally on Ubuntu 20.04. I have installed the following plugins:
- Docker plugin
- Docker pipeline
I have added a new docker cloud: Manage Jenkins -> Clouds -> New cloud -> Docker
I would like to pull docker images from the default Docker hub. The configuration looks this way:
Docker Cloud details:
- Docker Host URI is empty
- checkbox Enabled is checked
Docker Agent templates:
- Labels: dockerhub-ubuntu
- checkbox Enabled is checked
- Name: Dockerhub
- Docker Image: ubuntu:latest
- Remote File System Root: /home/jenkins
- User: jenkins
- checkbox Remove volumes checked
Everything else is default. I have a multibranch pipeline job which uses the following Jenkinsfile:
pipeline {
agent none
stages {
stage('Checkout') {
agent { label 'dockerhub-ubuntu'}
steps {
echo 'Checkout stage'
}
}
stage('Build') {
agent { label 'dockerhub-ubuntu'}
steps {
echo 'Build stage'
}
}
}
}
When I run the job I get the following console output:
Still waiting to schedule task
‘Jenkins’ doesn’t have label ‘dockerhub-ubuntu’
When I run the following Jenkinsfile everything works fine:
pipeline {
agent none
stages {
stage('Checkout') {
agent {
docker { image 'ubuntu:latest' }
}
steps {
echo 'Checkout stage'
}
}
stage('Build') {
agent {
docker { image 'ubuntu:latest' }
}
steps {
echo 'Build stage'
}
}
}
}
Why my docker agent template doesn’t work ?
2
Answers
Instead of
ubuntu:latest
tryjenkins/agent:latest-jdk17
or something based on that. Jenkins will try to launch an agent inside the container, not just run a job inside it, so requirements are different.It seems like Jenkins is unable to recognize the label
dockerhub-ubuntu
that you have configured for your Docker agent templateFirst, ensure that you have the latest versions of the Docker and Docker Pipeline plugins installed
Then you can ensure Docker is installed and running on the Jenkins host, and Jenkins has permission to access the Docker socket. Also both the Docker Cloud and the Docker Agent template should be enabled
dockerhub-ubuntu
should be unique and correctly applied to the Docker agent templateThe directory
/home/jenkins
should be writable by the jenkins userAfter ensuring your configuration matches the above, try running a simplified version of your Jenkinsfile to check if the Docker agent can be recognized
Also keep checking the Docker Daemon logs and Jenkins Logs
If the issue persists restart the Jenkins master to ensure all configuration changes take effect. Make sure that the Jenkins master has network access to Docker Hub and can pull images without any issues.