问题描述
Jenkins管道:我有一个管道p1
,它会触发作业j1
,然后触发作业j2
.我想要一些由j1
设置并传递给管道p1
中的j2
的参数.如何使用Jenkins管道插件实现此功能?预先感谢
Jenkins pipeline: I have a pipeline p1
that triggers a job j1
and then job j2
. I want some parameters that are set by j1
and passed to j2
in pipeline p1
. How do I implement this functionality using Jenkins pipeline plugin? Thanks in advance
推荐答案
可以使用"env"完成.如果您设法使j1
将其信息添加到构建的env
中.
It can be done using "env". If you manage to make j1
add its information into the build's env
.
如果j1
是管道,则可以访问env.MYKEY=MYVALUE
.对于自由式工作,它应该使用 EnvInject插件(didn不要尝试).在p1
中,如果您超出构建结果,则将获得包含该信息的地图.
If j1
was a pipeline you could to env.MYKEY=MYVALUE
.For a freestyle-job it should work using the EnvInject plugin (didn't try). In p1
then you will get a map with that information if you out of the build result.
因此,如果您在p1
中执行以下操作:
So, if you do in p1
something line this:
// somewhere in your pipeline, i.e. p1:
def j1BuildResult = build job: 'J1'
def j1EnvVariables = j1BuildResult.getBuildVariables();
然后j1EnvVariables
将是一个包含您在j1
中设置的变量的映射.
then j1EnvVariables
will be a map containing the variables you set in j1
.
PS:例如,如何将该信息作为参数p2
传递给在此处中进行了介绍.
PS: how to pass that info to as parameters p2
is e.g. covered here.
这篇关于将作业的参数/结果(通过管道触发)返回到同一管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!