Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins How to find the build number of the upstream build from downstream

I have two jobs in Jenkins:

  1. Job A: Build source + run unit tests, triggered by SCM changes. This is fast. It doesn't trigger anything by itself

  2. Job B: Build installer. This takes some time. It is triggered by monitoring successful builds of job A ("Build after other projects are built"). It uses artifacts from job A.

It can happen that several job A builds are started while a single run of Job B is in progress.

Job A #1 -> triggers Job B #1
                  |
Job A #2          |
                  |
Job A #3  -.      ` Job B #1 finishes
            `-> triggers Job B #2
Job A #4          |
                  |
Job A #5          |
 |                ` Job B #2 finishes
  `-----------> triggers job B #3

My question is: How can I figure out what build number of A triggered a certain build number of B, so in job B I can copy the artifacts from that exact build of job A?

The 'Copy Artifact' plugin allows specifying a specific build number, but where do I get it from?

like image 1000
Cristian Diaconescu Avatar asked Jul 31 '15 09:07

Cristian Diaconescu


2 Answers

One of least cumbersome and cheap ways to do this: you could pass the A ${BUILD_NUMBER} environment variable to B by using Parametrized Build plugin. For example, define PARENT_BUILD_NUMBER variable in B and the pass PARENT_BUILD_NUMBER=$BUILD_NUMBER from A to B.

like image 138
Zloj Avatar answered Nov 15 '22 08:11

Zloj


Of course the option was right there in the Copy Artifact plugin...

enter image description here

like image 39
Cristian Diaconescu Avatar answered Nov 15 '22 06:11

Cristian Diaconescu