title: Is it possible to set environment variables on a groovy function
body: <p>I know I can have an environment section on jenkins pipeline (declarative) for a stage.
  Like this:</p>
  
  <pre><code>stage('Name') {
      environment {
          NAME = value
      }   
      steps {
          script {
              Do something using these env vars
          }
      }
  } 
  </code></pre>
  
  <p>I want to write a groovy function, to define some env vars, and run something, and call it from a few pipelines.
  Something like:</p>
  
  <pre><code>def function () {
      environment {
          NAME = value
      }
      sh "do something using these env vars"
  }
  </code></pre>
  
  <p>Is it possible somehow?</p>
  
  <p>(I know I can write <code>sh "ENV=value; some CMD"</code> but I have few variables, and it is less read-able).</p>