Pass Jenkins Upstream Job Parameter to Downstream Job

Topic Tools

When we are implementing CI/CD through Jenkins, sometimes there is a need of passing parameter from one job to another job.

Here I am going to demonstrate how to achieve the same.

First of all, Install the Jenkins Parameterized Trigger Plugin – Go to Manage Jenkins and then Click on Manage Plugins

jenkins-windows-slave-creation-1

manage plugins

Once done, go to your Upstream Jenkins Job and add the Post Build Action to send the parameter to Downstream Job

Jenkins-Parameter-Upstream-Downstream-01 Jenkins-Parameter-Upstream-Downstream-02

Fill the Downstream Job details and Add the Parameter as “Predefined parameters

Jenkins-Parameter-Upstream-Downstream-03

Now go to your Downstream Job and use the Build Trigger Option as “This project is parameterised” and you can use the Upstream Build Parameters – I have used the Build Number of Upstream Job

Jenkins-Parameter-Upstream-Downstream-04

Using inside the Build Job

Jenkins-Parameter-Upstream-Downstream-05

Now, trigger the Upstream Job

Jenkins-Parameter-Upstream-Downstream-06

Once the Upstream Job completed, Jenkins will trigger the Downstream Job with the predefined Parameter

Jenkins-Parameter-Upstream-Downstream-07

In my Case the Build number of Upstream Job was 24 and Downstream Build number is 22 as shown in below screensshot of Downstream Job

Jenkins-Parameter-Upstream-Downstream-08

You can verify the result that Jenkins is using Upstream Build Number in my Downstream Job

Jenkins-Parameter-Upstream-Downstream-09

In the same fashion you can use other Upstream Build Parameters and use them in your Downstream Jobs and create the Build/Delivery Pipeline.

Hope you enjoyed today’s article.

Stay tuned for more learning ….

10 comments… add one

  • Kim

    Good Article 🙂

  • Pramod

    Very nice article

  • Hussain

    Goоd info. I’ve bookmarked it for later!

  • Nikhat

    Very nice, But what if i just want to copy parameter of Upstream job and check if that parameter is passed to another job then I have to kill that job, any suggestions here? i don’t want to trigger any build, I just want parameter of one job into other to check some condition. how do I do that?

    • Thanks Nikhat for your query.
      The main purpose of using Parameterized Trigger Plugin is to trigger the downstream build with upstream build’s parameters.
      If you want to just verify, you can either create a new build job and just display the parameters you need from upstream job.
      Or you can use ‘Conditional BuildStep Plugin
      Or you can simply add the “Execute shell” step in your downstream build at start which will test if the build is triggered with upstream job with given parameter (lets say runbuild=false) and if the value is passed as false from upstream just exit (without running further steps) the downstream build.
      You can use groovy scripting as well. There are multiple ways if you want to cancel/stop the build.
      Or you can use Jenkins Cause and use API to fetch the upstream job’s values

  • Nikhat

    Thank you so much Ravi for a very quick response…:-) I tried using conditional step plugin but I am stuck.
    Basically il tell you my scenario: I have job which disables all the jobs of that particular version passed in parameter , I have another build job in which I have a drop down list of versions I want to build, I want to block the build job if disabled job’s version is equal to version selected in build job from drop down.

    In execute Shell script in run condition plugin my version parameter(from disable job)value is coming blank.
    thanks alott… for help.

    • Hi Nikhat,
      Thanks for providing your requirement.
      Please could you elaborate what error you are getting and how are you passing the parameter and fetching in downstream job ?
      I believe you have followed the steps provided in this article and you have defined the correct syntax
      Someone wanted to trigger the job only if a concrete variable (i.e.: “VARIABLE”) has been defined so checking “invert” option and using the below condition worked for him:
      “${ENV,var=”VARIABLE”}true”
      Explanation: The conditional build expecting is just a “true” / other value, so if VARIABLE has no value it will leave a simple “true” in the field.
      Please see if this fits to your requirement, else please share the logs, conditions – thank you

  • Nikhat

    hi,
    I am trying to fetch value of job 1 from jenkins API but getting below issue:
    Traceback (most recent call last):
    File “”, line 1, in ?
    ImportError: No module named json

    • Have you configured the Jenkins Parameterized Trigger Plugin.

      Once done, go to your Upstream Jenkins Job and add the Post Build Action to send the parameter to Downstream Job
      Fill the Downstream Job details and Add the Parameter as “Predefined parameters”
      Now go to your Downstream Job and use the Build Trigger Option as “This project is parameterised” and you can use the Upstream Build Parameters

      I have used % since I was using Windows and $ will be used in *nix jobs.
      Please refer the post

      Then you can use the Upstream job’s parameter/variable in downstream job and then either use Conditional Step Plugin Or use any shell/python script to check the condition and terminate/proceed the rest of the steps

  • Misab

    Hello, nice share.

Leave a Comment