将作业的参数/结果(通过管道触发)返回到同一管道 [英] Return parameters/results from a job(triggered by pipeline) back to the same pipeline

查看:81
本文介绍了将作业的参数/结果(通过管道触发)返回到同一管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

这篇关于将作业的参数/结果(通过管道触发)返回到同一管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆