Jenkins: Sharing variables in MultiJob
You can pass the parameter BUILD_ID
by using Predefined parameters option in the multi-job phase.
Steps are as follows:
- Go to configure page, by clicking on Configure link of your multijob
- Click on Advanced button of the job where you want to pass the parameter;
- Click on Add Parameters, select Predefined parameters. Then create a parameter name of your own choice and assign the
BUILD_ID
to it; - Create the same parameter by enabling This build is parameterized option in downstream job where you want to receive the defined parameter. Then you can use the same in your script.
The question asks how to pass values between jobs for MultiJob projects, not Parameterized Trigger. Parameterized Trigger might not be a good solution because the downstream job will be executed outside of the scope of the MultiJob parent. To pass variables between MultiJob sub-jobs,
- Write variables to a property file in the first sub-job
- "Archive the artifacts" as post-build action in the first sub-job
- Between the first and second sub-jobs, insert an "Copy artifacts from another project" build. Set Project Name to the name of your first sub-job and Which Build to "Build triggered by current MultiJob build". Add your property file in "Artifacts to copy".
- In your second sub-job, under "Advanced...", Add parameters -> Parameters from properties file, and enter your property file name there. Your second phase will now have variables passed from your first phase.