title: Set environment variables from Groovy script in Jenkins
body: <p>I have got a FreeStyle project in Jenkins. One part of the build is an "Execute Groovy script" build step (important: not an 'Execute <strong>System</strong> Groovy script' step - that would not work). </p>
  
  <p>The calculations the script does are needed later on in other build stepes. How can I use variables along all steps? Is there a possibility to set environment variables in the "Execute Groovy script" that will be extracted later?</p>
  
  <p>I already tried to use </p>
  
  <pre><code>import hudson.EnvVars
  import hudson.model.*;
  ...
  def envvars = ['envVarName': 'envVarValue']
  build.environments.add(0, Environment.create(new EnvVars(envvars)))
  </code></pre>
  
  <p>but 'build' cannot be found in non-system groovy steps.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks a lot :)
  ian</p>