pass values from a freestyle/pipeline job upstream in jenkins2.0

和自甴很熟 提交于 2019-12-06 16:26:05

问题


Here is my problem simplified :

I have a main job (pipeline job) and I have x job (freestyle). In my main job I build x job using the following :

code in main job -

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

Now in this job x I change the value of JIRACHEF parameter and I print to check if it actually changed.:

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

This works in job x console output. I presume as per the solution presented, this updated value should be now available in the main job so I do the following after in main job just after building 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" thus making me believe it isn't actually passing the value upstream.

Note - I realize my job x is freestyle, but I have tried the above solution by making x pipeline job as well and still getting the same result - 'oldvalue'


回答1:


Main job - configuration: pipeline job

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: pipeline job

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

test2 - configuration: pipeline job, parametrized, two parameters aValue1FromX and aValue2FromX both strings

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


来源:https://stackoverflow.com/questions/41654143/pass-values-from-a-freestyle-pipeline-job-upstream-in-jenkins2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!