14
votes

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?

2
at least in blue ocean a solution exists: issues.jenkins-ci.org/browse/JENKINS-39628Roman Pickl
There is also a ticket with a lesser scope (visualization) issues.jenkins-ci.org/browse/JENKINS-47286 but at time of this comment being posted, it is being sadly ignored.Patrice M.
This can possibly be done by using the Simple Theme Plugin.mkobit

2 Answers

1
votes

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.

1
votes

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.