bitgandtter
bitgandtter

Reputation: 2329

Call parameterized Jenkins pipeline from another pipeline

There is any way to trigger a pipeline job from another pipeline with parameters, i already tried

build job: '/myjob', parameters: [string(name: 'param1', value:'val1')], wait: false

also tried

build job: 'myjob', parameters: [string(name: 'param1', value:'val1')], wait: false

and

build job: 'myjob', parameters: [[$class: 'StringParameterValue', name: 'param1', value: 'val1']], wait: false

with no luck, it says:

Item type does not support parameters

Upvotes: 8

Views: 26430

Answers (3)

Patrick
Patrick

Reputation: 519

The below worked for me in order to pass parameters "test_1" and "test_2" from pipeline "master" to pipeline "sub-1"

In the master pipeline

build job: 'sub-1', parameters: [[$class: 'StringParameterValue', name: 'test_1', value: 'nameValue'], [$class: 'StringParameterValue', name: 'test_2', value: 'valueValue']], wait: true

In the sub pipeline "sub-1" use by referencing the "params" variable

node {
   echo params.test_1
   echo params.test_2
}

Reference:

https://support.cloudbees.com/hc/en-us/articles/221400287-How-to-pass-parameter-to-downstream-job-in-Pipeline-job-

Upvotes: 1

Diego Castronuovo
Diego Castronuovo

Reputation: 29

Depending on your Jenkins job / pipeline structure, you should prefix the job with "../" e.g.:

build job: '../myjob/master', parameters: [string(name: 'param1', value:'val1')], wait: false

Upvotes: 0

bitgandtter
bitgandtter

Reputation: 2329

Since the subjob was another multibranch pipeline project i needed to specify the branch i wanted to run so with

build job: 'myjob/master', parameters: [string(name: 'param1', value:'val1')], wait: false

it now works

Upvotes: 17

Related Questions