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

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

问题描述

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 插件(没有试试).在 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天全站免登陆