Exercises to complete:
- Create a job inside a Jenkins
- Create a pipeline inside a job
- Add a label for a docker node
- Install Docker plugins
- Fix dial unix /var/run/docker.sock permissions
- Run the job
1. Create a jenkins pipeline inside the job
pipeline {
agent {
docker { image 'node:18.16.0-alpine' }
}
stages {
stage('Test') {
steps {
sh 'node --version'
}
}
}
}
2. Add a label docker, because the added docker node has label: docker
pipeline {
agent {
docker {
image 'node:18.16.0-alpine'
label 'docker'
}
}
stages {
stage('Test') {
steps {
sh 'node --version'
}
}
}
}
3. Fix issue: Invalid agent type specified. Must be one of [any, label, none] by installing Docker plugins:
- Docker Commons
- Docker API
- Docker
- Docker Pipeline
4. Run the job
5. Fix dial unix /var/run/docker.sock permissions for jenkins user on a docker node. Please note that you need to have sudo privileges or root access.
1
2
3
|
id jenkins
sudo usermod -aG docker jenkins
id jenkins
|
6. Restart docker on a docker node.
1
|
sudo systemctl restart docker.socket docker.service
|
7. Restart jenkins
1
|
sudo systemctl restart jenkins.service
|
8. Run the job
9. Change the operating system in pipeline and run the job again
pipeline {
agent {
docker {
image 'node:latest'
label 'docker'
}
}
stages {
stage('Test') {
steps {
cat /etc/os-release
sh 'node --version'
}
}
}
}
10. Run the job