title: Conditional environment variables in Jenkins Declarative Pipeline
body: <p>I'm trying to get a declarative pipeline that looks like this:</p>
  <pre><code>pipeline {
      environment {
          ENV1 = 'default'
          ENV2 = 'default also'
      }
  }
  </code></pre>
  <p>The catch is, I'd like to be able to override the values of <code>ENV1</code> or <code>ENV2</code> based on an arbitrary condition. My current need is just to base it off the branch but I could imagine more complicated conditions.</p>
  <p>Is there any sane way to implement this? I've seen some examples online that do something like:</p>
  <pre><code>stages {
      stage('Set environment') {
          steps {
              script {
                  ENV1 = 'new1'
              }
          }
      }
  }
  </code></pre>
  <p>But I believe this isn't setting the actually environment variable, so much as it is setting a local variable which is overriding later calls to <code>ENV1</code>. The problem is, I need these environment variables read by a nodejs script, and those need to be real machine environment variables.</p>
  <p>Is there any way to set environment variables to be dynamic in a jenkinsfile?</p>