Challenge - 5 Problems
Stage Conditions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of a stage with a simple when condition
Given the following Jenkins pipeline snippet, what will be the output if the branch name is 'feature-xyz'?
Jenkins
pipeline {
agent any
stages {
stage('Build') {
when {
branch 'main'
}
steps {
echo 'Building on main branch'
}
}
}
}Attempts:
2 left
💡 Hint
Check the branch name condition in the when directive.
✗ Incorrect
The when condition specifies the stage runs only on branch 'main'. Since the branch is 'feature-xyz', the stage is skipped.
🧠 Conceptual
intermediate2:00remaining
Understanding multiple conditions in when directive
Which of the following when conditions will cause the stage to run only if the branch is 'develop' and the build is triggered by a user?
Attempts:
2 left
💡 Hint
Look for the condition that requires both checks to be true.
✗ Incorrect
The allOf block requires all conditions inside to be true, so the stage runs only if branch is 'develop' and triggered by a user.
❓ Troubleshoot
advanced2:00remaining
Why does this when condition cause a syntax error?
Identify the error in this when directive snippet:
when {
branch == 'main'
}
Jenkins
when {
branch == 'main'
}Attempts:
2 left
💡 Hint
Check the correct syntax for branch condition in when directive.
✗ Incorrect
The when directive uses a keyword style like branch 'main', not an expression with '=='. Using '==' causes syntax error.
🔀 Workflow
advanced2:00remaining
Order of evaluation in multiple when conditions
Given this when directive, in what order are the conditions evaluated?
when {
allOf {
branch 'release'
environment name: 'DEPLOY_ENV', value: 'prod'
}
}
Attempts:
2 left
💡 Hint
Think about how allOf logically works in Jenkins when directive.
✗ Incorrect
Jenkins evaluates conditions in the order written inside allOf, so branch is checked first, then environment.
✅ Best Practice
expert2:00remaining
Choosing the best when condition for skipping stages on pull requests
You want to skip a stage when the build is triggered by a pull request. Which when condition is the best choice?
Attempts:
2 left
💡 Hint
Consider the official Jenkins way to detect pull requests.
✗ Incorrect
The changeRequest() condition is designed to detect pull requests. Using not { changeRequest() } skips the stage on PR builds.