Recall & Review
beginner
What is the purpose of the
when directive in a Jenkins pipeline stage?The
when directive controls whether a stage runs or is skipped based on specified conditions, helping to make pipelines more flexible and efficient.Click to reveal answer
beginner
Name two common conditions you can use inside the
when directive.You can use conditions like
branch to run a stage only on specific branches, and environment to run a stage only if an environment variable matches a value.Click to reveal answer
intermediate
How does the
when directive improve pipeline efficiency?By skipping stages that are not needed based on conditions, it saves time and resources, similar to deciding not to cook a meal if you already have leftovers.
Click to reveal answer
beginner
What happens if the
when condition in a stage evaluates to false?The stage is skipped and does not run, but the pipeline continues with the next stages.
Click to reveal answer
beginner
Write a simple example of a Jenkins stage that runs only on the 'main' branch using the
when directive.stage('Deploy') {
when {
branch 'main'
}
steps {
echo 'Deploying to production'
}
}
Click to reveal answer
What does the
when directive do in a Jenkins pipeline stage?✗ Incorrect
The
when directive controls whether a stage runs or is skipped based on conditions.Which condition would you use to run a stage only on a specific branch?
✗ Incorrect
The
branch condition runs the stage only on specified branches.If a
when condition is false, what happens to the stage?✗ Incorrect
The stage is skipped but the pipeline continues.
Which of these is NOT a valid
when condition in Jenkins?✗ Incorrect
There is no built-in
time condition in Jenkins when directive.How can you combine multiple conditions in a
when directive?✗ Incorrect
Jenkins supports combining conditions with
allOf (AND) and anyOf (OR).Explain how the
when directive helps control the flow of a Jenkins pipeline.Think about how you decide to do or skip tasks based on conditions in daily life.
You got /4 concepts.
Describe how you would use multiple conditions inside a
when directive to run a stage only on the 'main' branch and when an environment variable is set to 'production'.Combine conditions using <code>allOf</code> to require both to be true.
You got /4 concepts.