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

<pre><code>if (env.BRANCH_NAME == 'master') {
  // do steps here
} else {
  // do other steps here
}
</code></pre>

CC BY-SA 4.0
2019-07-15T09:55:51.357Z
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 https://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
Venkat Mani
CC BY-SA 4.0
2019-07-12T20:04:05.647Z
2019-07-12T20:04:05.647Z
jayhendren
<pre><code>stage('My Conditional Stage') {
    when {
        branch 'master'
    }
    steps {
        echo 'Do that only on master branch'
    }
}
</code></pre>

<p>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</p>

CC BY-SA 4.0
2019-07-12T11:23:26.217Z
I think your answer is here: https://stackoverflow.com/questions/38882135/groovy-switch-statement-with-list-of-values
Tensibai
CC BY-SA 4.0
2019-07-12T13:21:50.573Z
Hi , actually my question is same as this one https://stackoverflow.com/questions/45777169/jenkinsfile-conditional-stage-execution-in-the-script-pipeline-syntax ., is it possible to skip a stage with "When" like keyword in the scripted pipeline.
Venkat Mani
CC BY-SA 4.0
2019-07-12T13:25:39.627Z
Actually https://comquent.de/en/skipped-stages-in-jenkins-scripted-pipeline/ this holds the solution as well,
Venkat Mani
CC BY-SA 4.0
2019-07-12T13:27:58.667Z
Feel free to self answer here with enough details (not just a link, in doubt see [answer] )
Tensibai
<jenkins><jenkins-pipeline>
Can "When" like keyword be used in scripted pipeline?
Venkat Mani
# Can "When" like keyword be used in scripted pipeline?

(Asked by: username_0 on 2019-07-12)

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

**Tags:** jenkins, jenkins-pipeline

> **Comments:**
> **username_1**: I think your answer is here: https://stackoverflow.com/questions/38882135/groovy-switch-statement-with-list-of-values  
> **username_0**: Hi , actually my question is same as this one https://stackoverflow.com/questions/45777169/jenkinsfile-conditional-stage-execution-in-the-script-pipeline-syntax ., is it possible to skip a stage with "When" like keyword in the scripted pipeline.  
> **username_0**: Actually https://comquent.de/en/skipped-stages-in-jenkins-scripted-pipeline/ this holds the solution as well,  
> **username_1**: Feel free to self answer here with enough details (not just a link, in doubt see [answer] )  

---

## 1 answers

### Answer by username_2 on 2019-07-12. Score: 1

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
}

> **Comments:**
> **username_0**: 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 https://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  

---

