简体   繁体   English

在jenkins2.0中从上游传递自由样式/管道作业的值

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

Here is my problem simplified : 这是我简化的问题:

I have a main job (pipeline job) and I have x job (freestyle). 我有一份主要工作(管道工作),有x份工作(自由式)。 In my main job I build x job using the following : 在我的主要工作中,我使用以下命令构建x任务:

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.: 现在,在此作业x中,我更改了JIRACHEF参数的值,并打印以检查其是否实际更改。

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

This works in job x console output. 这适用于作业x控制台输出。 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: 我认为根据提出的解决方案,此更新的值现在应该在主作业中可用,因此在构建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. 应该打印“ newvalue”但打印“ oldvalue”,因此让我相信它实际上没有将值传递给上游。

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' 注意-我意识到我的工作x是自由式的,但是我也通过使x管道工作并且仍然得到相同的结果-'oldvalue'尝试了上述解决方案

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 test1-配置:管道作业

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

test2 - configuration: pipeline job, parametrized, two parameters aValue1FromX and aValue2FromX both strings test2-配置:管道作业,参数化,两个参数aValue1FromX和aValue2FromX均为字符串

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM