Complete the code to define a Jenkins pipeline stage named 'Build'.
stage('[1]') { steps { echo 'Building the project' } }
The stage block names the phase in the Jenkins pipeline. Here, 'Build' is the correct stage name.
Complete the code to specify the agent as a Docker container with the image 'python:3.8'.
pipeline {
agent {
docker {
image '[1]'
}
}
stages {
stage('Run') {
steps {
echo 'Running inside Docker'
}
}
}
}The image field specifies the Docker image to use for the agent. 'python:3.8' runs the pipeline inside a Python 3.8 container.
Fix the error in the Jenkinsfile snippet by completing the missing keyword to run shell commands.
pipeline {
agent any
stages {
stage('Test') {
steps {
[1] 'echo Testing the build'
}
}
}
}The sh step runs shell commands on Unix-like agents. It is required to execute shell commands in Jenkins pipelines.
Fill both blanks to create a Jenkins pipeline that triggers only when the branch is 'main' and the build result is successful.
pipeline {
agent any
triggers {
pollSCM('[1]')
}
stages {
}
post {
[2] {
echo 'Build succeeded on main branch'
}
}
}The pollSCM trigger uses a cron syntax like 'H/5 * * * *' to check for changes every 5 minutes. The success block runs steps only if the build succeeded.
Fill all three blanks to define a Jenkins pipeline environment variable, use it in a stage, and echo its value.
pipeline {
agent any
environment {
GREETING = '[1]'
}
stages {
stage('Say Hello') {
steps {
echo '[2]'
echo "$[3]"
}
}
}
}The environment variable GREETING is set to 'Hello, Jenkins!'. The echo step prints the variable name and then its value using ${GREETING}.