title: Jenkins Pipeline Conditional Stage based on Environment Variable
body: <p>I want to create a Jenkins (v2.126) Declarative syntax pipeline, which has stages with when() clauses checking the value of an environment variable. Specifically I want to set a Jenkins job parameter (so 'build with parameters', not pipeline parameters) and have this determine if a stage is executed. </p>
  
  <p>I have stage code like this:</p>
  
  <pre><code>stage('plan') {
    when {
       environment name: ExecuteAction, value: 'plan'
    }
    steps {
       sh 'cd $dir &amp;&amp; $tf plan'
    }
  }
  </code></pre>
  
  <p>The parameter name is ExecuteAction. However, when ExecuteAction is set via a Job "Choice" parameter to: plan, this stage does not run. I can see the appropriate value is coming in via environment variable by adding this debug stage:</p>
  
  <pre><code>stage('debug') {
    steps {
       sh 'echo "ExecuteAction = $ExecuteAction"'
       sh 'env'
    }
  }
  </code></pre>
  
  <p>And I get Console output like this:</p>
  
  <pre><code>[Pipeline] stage
  [Pipeline] { (debug)
  [Pipeline] sh
  [workspace] Running shell script
  + echo 'ExecuteAction = plan'
  ExecuteAction = plan
  [Pipeline] sh
  [workspace] Running shell script
  + env
  ...
  ExecuteAction=plan
  ...
  </code></pre>
  
  <p>I am using the when declarative syntax from <a href="https://jenkins.io/doc/book/pipeline/syntax/" rel="noreferrer">Jenkins book pipeline syntax</a>, at about mid-page, under the when section, built-in conditions. </p>
  
  <p>Jenkins is running on Gnu/Linux. </p>
  
  <p>Any ideas what I might be doing wrong?</p>