2

This works

steps.build "Job Name"

This doesn't work

steps.build "Job Name -p ParamKey1=ParamValue1 -p ParamKey2=ParamValue2"

I also tried this but no luck

steps.build "Job Name", parameters:[string(name: "Key1", value:"Value1")]

Any help would be appreciated.

  • 3
    See the [documentation](https://www.jenkins.io/doc/pipeline/steps/pipeline-build-step/) for the supported parameters, and [This Answer](https://stackoverflow.com/questions/36306883/how-can-i-trigger-another-job-from-a-jenkins-pipeline-jenkinsfile-with-github) for examples. – Noam Helmer Sep 29 '21 at 08:59

2 Answers2

0

This is my example on passing parameters to the child job:

stage('Deploy PROD') {
    steps {
      build job: 'PROD/Great-Project-Prod',
            propagate: true,
            wait: true,
            parameters: [
              //static parameter
              string(name: 'environment', value: 'prod'),
              //parameter from a function defined on top of the file
              string(name: 'projectVersion', value: getVersion()),
              //parameter coming from UI defined parameters
              string(name: 'envFileId', value: params.envFileId)
            ]
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
TudorIftimie
  • 1,050
  • 11
  • 21
0

Your code accesses steps through the steps object: steps.build. The string method used in the parameters block has the same visibility as build. It means you have to use the steps object to access it:

steps.build "Job Name", parameters: [
    steps.string(name: "Key1", value:"Value1")
]
agabrys
  • 8,728
  • 3
  • 35
  • 73