Complete the code to define a Jenkins pipeline block.
pipeline {
agent any
stages {
stage('Build') {
steps {
[1] 'echo Building...'
}
}
}
}The sh step runs shell commands in Jenkins pipelines.
Complete the code to specify the agent as a Docker container.
pipeline {
agent {
docker {
image '[1]'
}
}
stages {
stage('Test') {
steps {
sh 'echo Testing...'
}
}
}
}The image field specifies the Docker image to use as the agent environment.
Fix the error in the stage declaration by completing the missing keyword.
pipeline {
agent any
stages {
[1]('Deploy') {
steps {
sh 'echo Deploying...'
}
}
}
}The correct keyword to define a stage is stage.
Fill both blanks to create a post-build action that always runs a cleanup step.
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'echo Building...'
}
}
}
post {
[1] {
[2] {
sh 'echo Cleaning up...'
}
}
}
}The post block uses conditions like always and inside it the steps block defines commands to run.
Fill all three blanks to define an environment variable and use it in a shell step.
pipeline {
agent any
environment {
[1] = '[2]'
}
stages {
stage('Print') {
steps {
sh 'echo [3]'
}
}
}
}Define the variable name as MY_VAR, assign it the string HelloWorld, and use $MY_VAR to access it in shell.
