title: Environment variable exported in shell in groovy function can not be used
body: <p>I defined a Jenkins declarative pipeline as below:</p>
  
  <pre><code>def test(String A){
      sh """
      export tag="20190101"
      echo "${tag}"
      echo "${A}"
      """
  }
  pipeline{
      agent any
      stages{
          stage('check'){
              steps{
                  test("aaa")
              }
          }
      }
  }
  </code></pre>
  
  <p>if I use <code>double quote</code> as below, the command <code>echo "${A}"</code> will cause an error:</p>
  
  <pre><code>sh """
      export tag="20190101"
      echo "${tag}"
      echo "${A}"
      """
  </code></pre>
  
  <p>error like this:</p>
  
  <pre><code>groovy.lang.MissingPropertyException: No such property: tag for class: WorkflowScript
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
      at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458)
      at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:39)
      at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
      at WorkflowScript.test(WorkflowScript:4)
      at WorkflowScript.run(WorkflowScript:13)
      at 
  ....
  </code></pre>
  
  <p>So I changed the <code>double quote</code> to <code>single quote</code>, this time no error show, but I can get the variable pass from groovy, as below:</p>
  
  <pre><code>sh '''
      export tag="20190101"
      echo "${tag}"
      echo "${A}"
      '''
  </code></pre>
  
  <pre><code>[Pipeline] {
  [Pipeline] stage
  [Pipeline] { (check)
  [Pipeline] sh
  + export tag=20190101
  + echo 20190101
  20190101
  + echo 
  
  [Pipeline] }
  [Pipeline] // stage
  [Pipeline] }
  [Pipeline] // node
  [Pipeline] End of Pipeline
  </code></pre>
  
  <p>I think if use <code>single quote</code>, environment variables can be parse correctly, variable pass from groovy can not be parsed; if use <code>double quote</code>, variable pass from groovy can be parse correctly, but environment variable in shell can't be parsed and an error will be caused.
  However, I need to use variables both from shell environment which I set and pass from groovy, in my scenario, how to define the function with shell? Great thanks if you can help.</p>
  
  <p>Note:</p>
  
  <blockquote>
    <p>Jenkins 2.x<br>
    Declarative pipeline.</p>
  </blockquote>