Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does it possible to pass value from child job to parent on Jenkins?

Tags:

jenkins

I know it possible to pass values from parent to child jobs using Multijob Plugin

Is it possible to pass variables from child job to parent?

like image 322
Rudziankoŭ Avatar asked Dec 18 '25 20:12

Rudziankoŭ


1 Answers

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. In jobParent, you'll Inject Environment variables (in the BUILD step). https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin

At this time, if jobChild job created a .txt file with a variable for ex:

variableChild1=valueChild1

in it, then it'll be available/visible to the parent/upstrem job jobParent.

See the images for more details and run the jobs at your end to see the output.

enter image description here

and

enter image description here

like image 99
AKS Avatar answered Dec 20 '25 13:12

AKS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!