Reputation: 6041
I need to persist some build information within its enviroment variables as I did it before in a POFP (plain old freestyle project) with EnvInject action. The purpose is to be able to read them within other jobs.
I was under impression that in Jenkins Pipeline this comes out of the box.
Say, I have this Pipeline code:
AAA = '123'
env.BBB = '123'
def CCC = '123'
node('local_devkit'){
DDD = '123'
env.EEE = '123'
}
I ran this job and got a build. Then from the Jenkins Groovy Console I tried to access its environment:
b = Jenkins.instance.getItem('test').getBuildByNumber(1)
println b.environment
println b.envVars
I could see some automatic variables there like BUILD_NUMBER or JOB_URL. The problem is that I want to access my custom variables created in job runtime: AAA, BBB,... etc from my example.
Even the trick with adding a new ParametersAction doesn't help as the parameters are accessed differently in Jenkins Pipeline.
pa = new ParametersAction([
new StringParameterValue("QWERTY", 'AAAA')
])
currentBuild.rawBuild.addAction(pa)
How can I achieve the desired behavior?
Upvotes: 3
Views: 1757
Reputation: 25461
Your variables are being stored, though not I think accessible via the APIs you called. Exported via build REST, or via EnvAction
in Java, or as .buildVariables
in upstream Pipeline builds calling the build
step.
Upvotes: 1