Complete the code to specify a Docker agent in the Jenkinsfile.
pipeline {
agent {
docker {
image '[1]'
}
}
stages {
stage('Build') {
steps {
echo 'Building inside Docker container'
}
}
}
}The docker agent requires an image name. Here, node:14 is used as the Docker image.
Complete the code to add a custom Docker argument in the Jenkinsfile.
pipeline {
agent {
docker {
image 'python:3.8'
args '[1]'
}
}
stages {
stage('Test') {
steps {
echo 'Running tests inside Docker'
}
}
}
}The args field lets you pass extra Docker run options. Here, -v /tmp:/tmp mounts a volume.
Fix the error in the Jenkinsfile Docker agent declaration.
pipeline {
agent {
docker {
image '[1]'
}
}
stages {
stage('Deploy') {
steps {
echo 'Deploying inside Docker container'
}
}
}
}image key.The syntax for the Docker agent does not use a colon after image. The correct image name is node:14.
Fill both blanks to specify a Docker agent with a custom image and reuse the workspace.
pipeline {
agent {
docker {
image '[1]'
reuseNode [2]
}
}
stages {
stage('Build') {
steps {
echo 'Building with Docker agent'
}
}
}
}reuseNode to a string instead of boolean.The image is set to maven:3.6.3-jdk-11 and reuseNode is set to true to reuse the workspace.
Fill all three blanks to define a Docker agent with image, args, and label.
pipeline {
agent {
docker {
image '[1]'
args '[2]'
label '[3]'
}
}
stages {
stage('Test') {
steps {
echo 'Testing inside Docker container'
}
}
}
}The Docker agent uses the python:3.9-slim image, mounts the Docker socket with -v /var/run/docker.sock:/var/run/docker.sock, and uses the label docker-agent.