How to pass parameter to downstream job in Pipeline job?

Issue

I would like to pass a parameter value to a downstream job in a Pipeline job.
 

Environment

  • CloudBees Jenkins Enterprise
  • Pipeline

Resolution

Example:

Assume that I have a downstream freestyle job named downstream-freestyle, that contains two String parameters, named ParamA and ParamB.

In the upstream Pipeline job:

node {
    paramAValue = "paramAValue"
    paramBValue = "paramBValue"
    build job: 'downstream-freestyle', parameters: [[$class: 'StringParameterValue', name: 'ParamA', value: paramAValue], [$class: 'StringParameterValue', name: 'ParamB', value: paramBValue]]
}

Reference:

Have more questions? Submit a request

5 Comments

  • 0
    Avatar
    Tim Kalbas

    Although this answer is helpful if you're passing a string parameter, it would be even more useful if it showed the syntax for passing integers and other data type.

  • 0
    Avatar
    Wojciech Duda

    It would also be better if you knew how to find the name of the job you want to start. what if it is in another folder?

  • 0
    Avatar
    Denys Digtiar

    Tim/Wojciech,

    The best and easiest way to get the step right is to use Snippet Generator. It will give you an UI familiar from the Freestyle Projects and as a result a valid Pipeline code that you can just paste in your Pipeline.

  • 0
    Avatar
    Craig Rodrigues

    I have a job with about 25 parameters.

    Is there a way to pass all the parameters down to downstream jobs, instead of

    specifying each parameter inside the pipeline script's build command?

    Edited by Craig Rodrigues
  • 0
    Avatar
    Denys Digtiar

    Hi Craig,

    Defaults should kick in if you omit the parameter. Just supply the parameters that need overriding.

Please sign in to leave a comment.