Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2019-07-15T09:55:51.357Z
Answers: 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
Answers: Venkat Mani
Answers: CC BY-SA 4.0
Answers: 2019-07-12T20:04:05.647Z
Answers: 2019-07-12T20:04:05.647Z
Answers: jayhendren
Body: <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>
  
Comments: CC BY-SA 4.0
Comments: 2019-07-12T11:23:26.217Z
Comments: I think your answer is here: https://stackoverflow.com/questions/38882135/groovy-switch-statement-with-list-of-values
Comments: Tensibai
Comments: CC BY-SA 4.0
Comments: 2019-07-12T13:21:50.573Z
Comments: 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.
Comments: Venkat Mani
Comments: CC BY-SA 4.0
Comments: 2019-07-12T13:25:39.627Z
Comments: Actually https://comquent.de/en/skipped-stages-in-jenkins-scripted-pipeline/ this holds the solution as well,
Comments: Venkat Mani
Comments: CC BY-SA 4.0
Comments: 2019-07-12T13:27:58.667Z
Comments: Feel free to self answer here with enough details (not just a link, in doubt see [answer] )
Comments: Tensibai
Tags: <jenkins><jenkins-pipeline>
Title: Can "When" like keyword be used in scripted pipeline?
UserDisplayName: Venkat Mani
ThreadText: # 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  
  
  ---
  
  