Skipped stages in scripted Pipelines are not visible in the UI

1 minute readKnowledge base

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'); }

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' }