Issue
When using scripted pipeline syntax, stages that are skipped (e.g. due to a conditional) do not appear in Stage View, Blue Ocean, or CloudBees Pipeline Explorer.
Resolution
Declarative pipeline syntax using the when
condition is recommended if visible skipped stages are required.
For more details on the when
directive, and an example how to use it, see Using Declarative Pipeline syntax
Workaround
If using scripted Pipeline syntax, a catchError
step can be used to emulate a visible skipped stage:
catchError(catchInterruptions: false, buildResult: null, stageResult: 'NOT_BUILT'){ error('Skipping this stage'); }
See here for more details on the catchError
step: https://www.jenkins.io/doc/pipeline/steps/workflow-basic-steps/#catcherror-catch-error-and-set-build-result-to-failure
Example Scripted Pipeline:
stage('Hello Scripted') { echo 'Hello Scripted World' } stage('Scripted Skip') { if (true) { // TODO update this conditional catchError(catchInterruptions: false, buildResult: null, stageResult: 'NOT_BUILT') { error('Skipping this stage'); } } else { echo 'Not Skipped' } } stage('Post Scripted Skip') { echo 'Done' }