Friday, June 10, 2016

Jenkins - Passing Parameter in Build Pipeline

So you use Jenkins to create build pipeline, and triggers either automatically or manually downstream jobs. Somewhere down the pipeline, a triggered job needs to use parameters from previous step. How do you achieve that?

Let us use an example, we have three jobs in our example pipeline:
1. serverBuild - build the lastest rpm
2. serverDeploy - deploy the lastest rpm to prod
3. serverRollback - anything goes wrong, we want to rollback

So in order to rollback one version down, you need to pass the rpm version to the build pipeline, so that when you call serverRollback, it can rollback to the given version.

The trick here is to somehow write the version number into a file in job1, let's say "parameter_file", then pass it down to job2, job2 use it as a env variable, which will be automatically available in job3.

In job1 Build steps:
I use "Execute shell":
# echo "rollback_version=version_number" > parameter_file
# parameter_file will contain ""

Now this "parameter_file" will be generated in job1's workspace and available for job2

In Post-build Actions, enable:
1. "Current build parameters"
2. "Build on the same node"

Then "Add Parameters", choose:
“Parameters from properties file”

In job2, what you need to do is just add a text parameter:

this will automatically be added into env variable, so you can just use ${rollback_version} in job3

I hope my explaination is clear enough, but if you have any questions, shoot me an email at

1 comment:

Anonymous said...

thanks for shared wonderful information of giving best information.its more useful and more helpful. great doing keep sharing
CCNA Training in Chennai