如何在 Jenkins 上将价值从孩子的工作传递给父母?

Rud*_*koŭ 3 jenkins

我知道可以使用Multijob Plugin将值从父作业传递到子作业

是否可以将变量从子作业传递给父作业?

Aru*_*gal 5

Yes with a little work. If JobParent calls jobChild and you want to have variableChild1 (that you may have created in jobChild job) to be visible in jobParent job then do the following simple steps.

  1. In the child job, create a file (variable=value) pair with all the variables in it. Lets call it child or downstream_job or jobChild_envs.txt

  2. Now, once jobParent is done calling jobChild (I guess you are calling Trigger another project or Build other project steps etc), next action just would be to use "Copy Artifact from another project/job" (Copy Artifact plugin in Jenkins). PS: You would need to click on the check box to FLATTEN the file (see jobParent image below). https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin

    Using this plugin, you'll be able to get a file/folder from jobChild's workspace into jobParent's workspace in a defined/base workspace location.

  3. 在 jobParent 中,您将注入环境变量(在 BUILD 步骤中)。 https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin

这时候,如果jobChild作业创建了一个.txt文件,里面有一个变量为ex:

variableChild1=valueChild1
Run Code Online (Sandbox Code Playgroud)

在其中,然后它对父/上游作业 jobParent 可用/可见。

有关更多详细信息,请参阅图像并在最后运行作业以查看输出。

在此处输入图片说明

在此处输入图片说明