9

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

Ligio
  • 607
  • 2
  • 7
  • 14

4 Answers4

12

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.
Aefix
  • 177
  • 1
  • 8
6

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.
sattva_venu
  • 677
  • 8
  • 22
3

To use the suggestion i am going to describe, you will need Parameterized Trigger plugin. One way to pass custom parameter to a downstream job is by storing the key & value pair (key=value) in a file and specifying the same file by selecting Parameters from properties file option while calling downstream (in this example, job B) job. Refer the screenshot below:

enter image description here

Now you can access the variable in downstream job 'B' by using $BUILD_ID. You would also like to enable the option Don't trigger if any files are missing.

Technext
  • 7,887
  • 9
  • 48
  • 76
  • 7
    I see this is accepted answer, does it really answers the question though? I have exactly the same situation as @Ligio which is a **MultiJob** and need to pass argument from _build_ to _deploy_ job. Value comes from _build_ job but _deploy_ job **is not a downstream** job of _build_ job. They are run in sequence indeed but as phases of the parent **MultiJob**. Moreover, they run on different slave machines. I can't see how this solution would work. Any tips would be appreciated. [It looks like that.](https://s21.postimg.org/x82wux0qv/multijob.png) – topr Aug 26 '16 at 10:42
  • 1
    @topr I have the same issue too. Any progress or workaround on that?? – polavishnu Nov 25 '16 at 08:03
  • @polavishnu Yes, each phase job has a few env variables added on the multi job level. For the case in the question it would be sufficient to pass a value of BUILD_JOB_BUILD_ID (or BUILD_JOB_BUILD_NUMBER, don't remember exactly) environment variable to the Install Job. – topr Dec 06 '16 at 18:36
  • My problem is that in my build phase I have to jobs building release and debug. But the name of the job is the same. Kind of the build is set by parameters. But in the deploy phase I need to copy the artefacts from the build_job (building the debug) and build_job (building release). :/ – Stefan Peter Feb 15 '17 at 09:15
1

First you need add to the "install job" a string parameter called "BUILD_ID" and then once your build job is done you can "Trigger Parametrized build on on other project " and add the parameter of the next build being the BUILDID=%BuildID%

For more info on paramterized job on Jenkins read the following link: https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build

you might need to install a plugin for that. Link above.

AltF4_
  • 2,312
  • 5
  • 36
  • 56