Jenkins "Stage skipped due to when conditional" in CI
This is not an error but a frequent surprise: a stage you expected to run shows Stage "X" skipped due to when conditional. The Declarative when {} for that stage evaluated to false, usually a branch, environment, or expression that did not match the actual build.
What this error means
The build succeeds but a key stage (deploy, release) never executes, and the log shows Stage "Deploy" skipped due to when conditional.
Jenkins console
[Pipeline] stage
[Pipeline] { (Deploy)
Stage "Deploy" skipped due to when conditional
[Pipeline] }Common causes
A branch / environment condition did not match
A when { branch 'main' } skips on any other branch; when { environment ... } skips when the variable differs from the expected value.
A custom expression returned false
A when { expression { ... } } whose Groovy evaluates to a falsy value (empty string, null, false) skips the stage silently.
How to fix it
Inspect and correct the when condition
- Echo the values the
whenblock tests (env.BRANCH_NAME, parameters) right before the stage. - Adjust the condition to match the real build context, or use
beforeAgent trueso an agent is not allocated for skipped stages. - For complex logic, replace
expressionwith explicit conditions you can reason about.
Jenkinsfile
stage('Deploy') {
when { branch 'main'; beforeAgent true }
steps { sh './deploy.sh' }
}How to prevent it
- Log the inputs a
whenblock evaluates so skips are explainable. - Use
beforeAgent trueto avoid allocating agents for skipped stages. - Test
whenexpressions for the branches and parameters you expect.
Related guides
Jenkins input step "Rejected by" / aborted by user in CIFix Jenkins pipelines that fail at an `input` step with "Rejected by <user>" / "org.jenkinsci.plugins.workflo…
Jenkins multibranch "Jenkinsfile not found" / no Jenkinsfile in CIFix Jenkins multibranch / pipeline-from-SCM "ERROR: ... Jenkinsfile not found" - the configured script path d…
Jenkins "java.lang.StackOverflowError" in a CPS pipeline in CIFix Jenkins "java.lang.StackOverflowError" raised during pipeline execution - deep or recursive Groovy under…