Complete the code to define a Jenkins pipeline stage named 'Build'.
stage('[1]') { steps { echo 'Building the project' } }
The stage name should be 'Build' to represent the build step in the pipeline.
Complete the code to add a post-build action that always runs.
post {
[1] {
echo 'Cleaning up workspace'
}
}The 'always' block runs regardless of the build result, ensuring cleanup happens every time.
Fix the error in the pipeline syntax to correctly define an agent.
pipeline {
agent [1]
stages {
stage('Test') {
steps {
echo 'Running tests'
}
}
}
}The agent should be specified as any without quotes to indicate any available agent.
Fill both blanks to create a stage that runs only when the branch is 'main'.
stage('Deploy') { when { [1] '[2]' } steps { echo 'Deploying to production' } }
The when condition uses branch 'main' to run the stage only on the main branch.
Fill all three blanks to define a pipeline with an agent, environment variable, and a stage.
pipeline {
agent [1]
environment {
APP_ENV = '[2]'
}
stages {
stage('[3]') {
steps {
echo "Environment is $APP_ENV"
}
}
}
}The pipeline uses agent any to run on any agent, sets APP_ENV to 'production', and defines a 'Deploy' stage.