Accessing user build variables of another build

12 views
Skip to first unread message

Yasin Jamal

unread,
Aug 14, 2019, 9:37:58 AM8/14/19
to jenkins...@googlegroups.com
Hi,

We have Jenkins 2.0 , Scripted Pipeline and i want to 

1. Push an environment variable VAR1=FOO in a Job A, and
2. Access that environment variable from another Job B.

Job A and B both are independent.

When I invoke Job B, I want to go and find the latest build of Job A and then read the value of VAR1.

I tried the below that gives me the 'lastbuld of JobA' but how do i access VAR1 of JobA ?

def currentJob = Jenkins.instance.getItemByFullName('JobA')
def build = currentJob.getLastBuild()

Tried build.getEnvironment() but that gives me environment variables of JobA, NOT the one that I set. Also tried buld.getBuildVariables() but it throws error. I believe the getBuildVariables() method is for 'downstream' jobs.

Any idea how do i do this ?

BTW: I am seeting VAR1=FOO in JobA as env.VAR1="FOO"

Any help much appreciated.

Thanks.

Martin d'Anjou

unread,
Aug 18, 2019, 11:51:25 AM8/18/19
to Jenkins Users
Reply all
Reply to author
Forward
0 new messages