There are two ways to pass parameters between two jobs. First method is to configure the parameters within first job. These variables are configured with hard-coded values.
The second method is configuring the job to accept parameters at runtime. It allows you to pass different value each time you run the job without making any change in the job configuration.
This article is a step by step approach on using the second method in Jenkins.
- Install Parameterized Trigger Plugin, if not already done.
- Create two jobs by name Project1 and Project2.
- Click on Project1 job and then click on Configure link in the left side.
- You’ll see a new option – This build is parameterized. Enable that option
- Now you need to select the type of parameter from the list of available parameters.
- I’ll select String Parameter and configure it.
- Specify the parameter name, default value and description.
- In this example, I’m passing SVN Revision number to the target job to check-out the code from.
- The parameter name is SVN_REVISION, default value is 124 and description to understand the job.
- We need to call the target job which will consume this parameter.
- Go to Build section and click on Add build step option.
- Select the option Trigger/call builds on other projects from the dropdown.
- Specify the name of the target job, it will be Project2 in this example.
- Pass the parameter we captured above, i.e. SVN_REVISION by selecting Current build parameters option.
- By doing this, variable name SVN_REVISION will be passed to Project2 with the value you provide at runtime.
- Click on Save to save the changes.
- Click on Project2 from Jenkins Dashboard.
- You’ll see a new option on the left side – Build with Parameters.
- Click on that option and you’ll be prompted to pass value.
- If you don’t provide any value, then 123 will be passed to the target job.