Roman Pickl
Roman Pickl

Reputation: 645

Better visualization of skipped stages in declarative pipeline

I'm looking into moving our scripted pipelines to declarative pipelines.

I'm using the when key word to skip stages

stage('test') {       
     // Only do anything if we are on the master branch
     when { branch 'master' }
     //...
}

This works, however the skipped stage is shown as green. I would prefer if it was shown as gray in the pipeline overview. Is there a way to achieve this?

Upvotes: 14

Views: 4944

Answers (2)

Zach Goodman
Zach Goodman

Reputation: 46

If the stage is appearing green for you then it's likely still actually running. A skipped stage should look like this in the Jenkins classic stage view. Consider the following code sample, which has three stages, the middle stage being skipped conditionally with the when directive.

pipeline {
    agent any
    stages {
        stage('Always run 1') {
            steps { echo "hello world" }
        }
        stage('Conditionally run') {
            when {
                expression { return false }
            }
            steps { echo "doesn't get printed" }
        }
        stage("Always run 2") {
            steps { echo "hello world again" }
        }
    }
}

This should produce the following line in your build log

Stage "Conditionally run" skipped due to when conditional

Another answerer of this question mentioned Blue Ocean, which definitely presents a beautiful presentation of the stage view. Here is an image of how a skipped stage looks in the Blue Ocean stage view. Note that Blue Ocean is a UI and your job's underlying pipeline code will be the same regardless of which UI you choose to use.

Upvotes: 1

saw303
saw303

Reputation: 9082

As you mentioned in your comment I suggest you to use Jenkins Blue Ocean when working with pipelines.

It provides a more modern and user friendly view for your pipeline projects. Even the pipeline itself is display in a much more convenient way.

Upvotes: 1

Related Questions