5

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?

1 Answer 1

12

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.

Sign up to request clarification or add additional context in comments.

4 Comments

what type of parameters you created on JobB for JOBNAME and BUILDNUM ? String ? Empty Default ?
It was String Parameter.
When I tried this, it didn't pass the build number correctly. e.g. instead of the build number "201906041" that was generated as configured under "Create a formatted build number" it passed the raw build number "195". Any suggestions how I would correct the configuration to fix that?
hmm interesting. I've never tried formatted build numbers before, Are you doing something like this : stackoverflow.com/questions/45252515/…? I'm guessing It might be stored under a different name in the environment variables.. try passing that instead

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.