Pass values ​​from freestyle / pipeline job upstream in jenkins2.0

Here is my problem:

I have the main job (working with the pipeline) and I have x job (freestyle). In my main work, I create an x ​​job using the following:

the code in the main task is

res = build job: 'x', parameters: [string(name: 'JOBNAME', value: string(name: 'JIRACHEF', value: "oldvalue")], quietPeriod: 2 

Now in this task x, I change the value of the JIRACHEF parameter, and I print to check if it really has changed:

  os.environ["JIRACHEF"] = "newvalue" print os.environ["JIRACHEF"] 

This works when outputting the x console of the job. I assume that in accordance with the solution presented, this updated value should now be available in the main task, so I will do the following after the main task right after creating x:

 res = build job: 'x', parameters: [string(name: 'JOBNAME', value: string(name: 'JIRACHEF', value: "oldvalue")], quietPeriod: 2 print "$res.buildVariables" 

which should print "newvalue" but prints "oldvalue", which leads me to believe that it does not actually pass the value upstream.

Note. I understand that my work x is freestyle, but I tried the above solution, also doing work with the x pipeline and still get the same result - "oldvalue"

0
source share
1 answer

The main task - configuration: work with the conveyor

 node { x = build job: 'test1', quietPeriod: 2 build job: 'test2', parameters: [ string(name: 'aValue1FromX', value: "$x.buildVariables.value1fromx"), string(name: 'aValue2FromX', value: "$x.buildVariables.value2fromx") ], quietPeriod: 2 } 

test1 - configuration: work with the pipeline

 node { env.value1fromx = "bull" env.value2fromx = "bear" } 

test2 - configuration: pipeline job, parameterized, two parameters aValue1FromX and aValue2FromX both lines

 node { echo "$env.aValue1FromX" echo "$env.aValue2FromX" } 
0
source

Source: https://habr.com/ru/post/1262444/


All Articles