How to invoke a jenkins pipeline A in another jenkins pipeline B

Yash picture Yash · Apr 11, 2017 · Viewed 59.5k times · Source

I have two Jenkins pipelines, let's say pipeline-A and pipeline-B. I want to invoke pipeline-A in pipeline-B. How can I do this?

(pipeline-A is a subset of pipeline-B. Pipeline-A is responsible for doing some routine stuff which can be reused in pipeline-B)

I have installed Jenkins 2.41 on my machine.

Answer

Matias Snellingen picture Matias Snellingen · Apr 11, 2017

A little unclear if you want to invoke another pipeline script or job, so I answer both:

Pipeline script The "load" step will execute the other pipeline script. If you have both scripts in the same directory, you can load it like this:

def pipelineA = load "pipeline_A.groovy"
pipelineA.someMethod()

Other script (pipeline_a.groovy):

def someMethod() {
    //do something
}

return this

Pipeline job

If you are talking about executing another pipeline job, the "build job" step can accomplish this:

build job: '<Project name>', propagate: true, wait: true

propagate: Propagate errors

wait: Wait for completion

If you have paramters on the job, you can add them like this:

build job: '<Project name>', parameters: [[$class: 'StringParameterValue', name: 'param1', value: 'test_param']]