stage('My Conditional Stage') {
    when {
        branch 'master'
    steps {
        echo 'Do that only on master branch'

For Scripted pipeline ; if value of i is 0 then we need skip the stages ; obviously we can put a conditional logic by surrounding the stage but if we do that the UI doesn't show it like it skipped


A Scripted Pipeline is literally a Groovy script, so you can just use if/else conditionals like you would in a normal Groovy script.

if (env.BRANCH_NAME == 'master') {
  // do steps here
} else {
  // do other steps here
  • Thanks, Yes Scripted is a groovy script, we can do the conditional logic like you mentioned but the Blue Ocean UI Perspective is the concern here. i.e skipped stages are not showing differently when we use "if" condition in Scripted but in the declarative it will be like look different if we use "when". Actually this article comquent.de/en/skipped-stages-in-jenkins-scripted-pipeline found solution for open source jenkins ., but this piece of shared library is not working for cloudbees jenkins enterprise Jul 15 '19 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.