Issue
I have got a FreeStyle project in Jenkins. One part of the build is an "Execute Groovy script" build step (important: not an 'Execute System Groovy script' step - that would not work).
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?
I already tried to use
import hudson.EnvVars
import hudson.model.*;
...
def envvars = ['envVarName': 'envVarValue']
build.environments.add(0, Environment.create(new EnvVars(envvars)))
but 'build' cannot be found in non-system groovy steps.
Any ideas?
Thanks a lot :) ian
Solution
The execute groovy script step simply runs a groovy script on the agent. It is the same idea as running a shell script on the agent: it's not running in the Jenkins master, so there is no concept of a Jenkins build environment. If you want this step to pass information to a next one, the easiest is probably to write the values you want to share to a file in the workspace.
Answered By - Mzzl
Answer Checked By - David Goodson (JavaFixing Volunteer)