Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass the Job name and build number as parameter to another jenkins job?

Tags:

jenkins

I have two Jenkins Jobs - JobA and JobB.

I need to start execution of JobB when JobA has finished building and I need to pass the Job name (i.e. 'JobA') and the latest build number (the build that just completed) to JobB.

Along with these, I also need to pass the original parameters that were passed to JobA, to be passed to JobB

I have added a post build action in JobA - Trigger parameterized build on other projects and specified JobB in the projects to build. within this, I have also added a parameter - Current build parameters, which will pass the current parameters to the next job.

I have also added a build trigger in JobB - Build after other projects are built and specified JobA as the Project Name.

Now, how do I pass the jobName and buildNumber of JobA to JobB?

like image 621
Sumit Avatar asked Jul 13 '17 23:07

Sumit


1 Answers

So, I was able to figure this out myself:

I created 2 String parameters in JobB - JOBNAME and BUILDNUM

Then, in the Trigger parameterized build on other projects section within the Post-build Action of JobA, I added two things:

  1. Current Build Parameters
  2. Predefined Parameters

Predefined paramters:

JOBNAME=${JOB_NAME}
BUILDNUM=${BUILD_NUMBER}

Using these, I was able to pass the job name and build number along with all the current parameters to the next job.

like image 167
Sumit Avatar answered Nov 15 '22 08:11

Sumit