Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 496
Yash Avatar asked Apr 11 '17 04:04

Yash


People also ask

How do you trigger a Jenkins pipeline from another pipeline?

You can follow the below steps to trigger a Jenkins pipeline in another Jenkins pipeline. Select a job that triggers a remote one and then go to Job Configuration > Build section > Add Build Step > Trigger builds on remote/local projects option.

How do I call one Jenkins job from another Jenkins job?

Now just go to your source Jenkins job and Click Configure button. Under Build Section, Add Trigger a remote parameterized job as a build step. Then select the Destination Jenkins name that we just added, give the job name that you want to trigger at destination Jenkins(here it is test ) and parameters.

How do I connect two pipelines in Jenkins?

One approach is to use the Locks and Latches plugin and give each of the jobs on each pipeline their own Lock eg Pipeline-A and Pipeline-B, then the job that runs the tests is configured to obtain the lock on both Pipeline-A and Pipeline-B.


1 Answers

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']] 
like image 106
Matias Snellingen Avatar answered Sep 20 '22 13:09

Matias Snellingen