Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins: Sharing variables in MultiJob

I'm using Jenkins for testing/build purposes, so I created a MultiJob project with this configuration:

  1. Test Job
  2. Build Job
  3. Install Job

The MultiJob is launched from the Master Jenkins, but other jobs are launched from other Nodes. The Build Job executes a shell script which creates the BUILD_ID. Now, I want the BUILD_ID to be passed as parameter to the Install Job. How can I do that? My only choice is to use a property file?

Thanks a lot

like image 285
Ligio Avatar asked Sep 19 '14 08:09

Ligio


People also ask

How can you pass parameters from one job to another job in Jenkins?

You can use Parameterized Trigger Plugin which will let you pass parameters from one task to another. You need also add this parameter you passed from upstream in downstream.

How do you transfer workspace and environment variables in a pipeline to the next job?

Under Build Environment check Set environment variables through a file. give the path of that file here. If the environment variable is created in the first job then again you can save all the environment variable in a file and browse it using the above method. Install this plugin and go to job configuration paeg.

Where are Jenkins environment variables stored?

These variables are either set by the shell/system or by you in ~/. bashrc , ~/. bash_profile . There are also environment variables set by Jenkins when a job executes, but these are not displayed in the System Information.


1 Answers

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,

  1. Write variables to a property file in the first sub-job
  2. "Archive the artifacts" as post-build action in the first sub-job
  3. 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".
  4. 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.
like image 67
Aefix Avatar answered Oct 22 '22 10:10

Aefix