Answers: <p>It would seem not - in the scripted pipeline, groovy needs to be used - see <a href="https://jenkins.io/doc/book/pipeline/syntax/#flow-control" rel="nofollow noreferrer">the docs</a></p>
  
  <pre class="lang-java prettyprint-override"><code>node {
      stage('Example') {
          if (env.BRANCH_NAME == 'master') {
              echo 'I only execute on the master branch'
          } else {
              echo 'I execute elsewhere'
          }
      }
  }
  
  </code></pre>
  
  <p>(taken straight from the docs)</p>
  
  <p>This would be the same as <code>when { branch 'master' }</code></p>
  
Answers: CC BY-SA 4.0
Answers: 2020-03-31T14:10:22.140Z
Answers: Thanks Bruce for sharing this. Well, it is obvious that one can write a code which behaves like when conditions, however both when statement and its conditions are written in java (or maybe even groovy) and, I believe, should be available from a groovy pipeline as well.
Answers: Dima
Answers: CC BY-SA 4.0
Answers: 2023-04-16T23:54:10.997Z
Answers: @mangolier Those built-in keywords like `stage` and `node` are called steps. You can see all the steps available for a scripted pipeline on this page https://www.jenkins.io/doc/pipeline/steps/ . There is no `when` step.
Answers: Levi
Answers: CC BY-SA 4.0
Answers: 2020-03-31T13:52:11.150Z
Answers: 2020-03-31T13:52:11.150Z
Answers: Bruce Becker
Body: <p>Jenkins declarative pipelines offer very convenient <strong>when</strong> directive with conditions like <strong>changeset</strong>.</p>
  
  <p>Is is possible the this changeset and other when conditions in a scripted pipeline?</p>
  
Tags: <jenkins><jenkins-pipeline><jenkinsfile>
Title: Using Jenkins declarative when conditions in scripted pipelines
UserDisplayName: Dima
ThreadText: # Using Jenkins declarative when conditions in scripted pipelines
  
  (Asked by: username_0 on 2020-03-31)
  
  Jenkins declarative pipelines offer very convenient **when** directive with conditions like **changeset**.
  
  Is is possible the this changeset and other when conditions in a scripted pipeline?
  
  **Tags:** jenkins, jenkins-pipeline, jenkinsfile
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-03-31. Score: 1
  
  It would seem not - in the scripted pipeline, groovy needs to be used - see [the docs](https://jenkins.io/doc/book/pipeline/syntax/#flow-control)
  
  ```java
  node {
      stage('Example') {
          if (env.BRANCH_NAME == 'master') {
              echo 'I only execute on the master branch'
          } else {
              echo 'I execute elsewhere'
          }
      }
  }
  
  ```
  
  (taken straight from the docs)
  
  This would be the same as `when { branch 'master' }`
  
  > **Comments:**
  > **username_0**: Thanks username_1 for sharing this. Well, it is obvious that one can write a code which behaves like when conditions, however both when statement and its conditions are written in java (or maybe even groovy) and, I believe, should be available from a groovy pipeline as well.  
  > **username_2**: @mangolier Those built-in keywords like `stage` and `node` are called steps. You can see all the steps available for a scripted pipeline on this page https://www.jenkins.io/doc/pipeline/steps/ . There is no `when` step.  
  
  ---
  
  