Complete the code to specify the Docker agent in a Jenkins pipeline.
pipeline {
agent {
docker {
image '[1]'
}
}
stages {
stage('Build') {
steps {
echo 'Building inside Docker container'
}
}
}
}The image field specifies the Docker image to use for the agent. Here, ubuntu:latest is a common base image.
Complete the code to run a shell command inside the Docker agent.
pipeline {
agent {
docker {
image 'python:3.8'
}
}
stages {
stage('Test') {
steps {
sh '[1]'
}
}
}
}The sh step runs a shell command inside the Docker container. Here, python --version checks the Python version inside the container.
Fix the error in the Docker agent declaration to correctly specify the Docker image.
pipeline {
agent {
docker {
image [1]
}
}
stages {
stage('Deploy') {
steps {
echo 'Deploying application'
}
}
}
}The image value must be a string enclosed in quotes. Using single quotes like 'nginx:latest' is correct.
Fill both blanks to define a Docker agent with a custom label and reuse the same image in a stage.
pipeline {
agent {
docker {
image [1]
label [2]
}
}
stages {
stage('Build') {
agent {
docker {
image 'myapp:latest'
}
}
steps {
echo 'Building inside Docker'
}
}
}
}The image is set to 'myapp:latest' to specify the Docker image. The label is set to 'docker-agent' to identify the agent node.
Fill all three blanks to create a Docker agent with arguments, reuse the image, and run a command inside the container.
pipeline {
agent {
docker {
image [1]
args [2]
}
}
stages {
stage('Test') {
steps {
sh '[3]'
}
}
}
}The image is 'node:16'. The args specify running as root user with '-u root:root'. The shell command npm test runs tests inside the container.