Complete the code to specify the Docker agent in Jenkins pipeline.
pipeline {
agent {
docker { image '[1]' }
}
stages {
stage('Build') {
steps {
sh 'echo Building inside Docker'
}
}
}
}The docker { image 'nodejs:14' } directive tells Jenkins to run the build inside a Node.js 14 Docker container, ensuring a consistent environment.
Complete the code to run a shell command inside the Docker container in Jenkins.
pipeline {
agent {
docker { image 'python:3.8' }
}
stages {
stage('Test') {
steps {
sh '[1]'
}
}
}
}The command pytest tests/ runs tests inside the Docker container, ensuring tests run in a consistent environment.
Fix the error in the Docker agent declaration to ensure the build runs inside the container.
pipeline {
agent {
docker {
[1] 'maven:3.6.3-jdk-11'
}
}
stages {
stage('Build') {
steps {
sh 'mvn clean install'
}
}
}
}The correct syntax is docker image 'maven:3.6.3-jdk-11' to specify the Docker image for the agent.
Fill both blanks to define a Docker agent with a custom label and reuse the container.
pipeline {
agent {
docker {
image '[1]'
[2] true
}
}
stages {
stage('Deploy') {
steps {
sh 'echo Deploying application'
}
}
}
}Setting image 'nodejs:16' specifies the Docker image, and reuseNode true tells Jenkins to reuse the container for faster builds.
Fill all three blanks to create a Docker pipeline that builds, tests, and cleans up.
pipeline {
agent {
docker {
image '[1]'
args '[2]'
reuseNode [3]
}
}
stages {
stage('Build') {
steps {
sh 'make build'
}
}
stage('Test') {
steps {
sh 'make test'
}
}
}
post {
always {
sh 'make clean'
}
}
}The pipeline uses golang:1.18 as the Docker image, passes --network host as Docker arguments, and sets reuseNode true to reuse the container.