How to invoke a jenkins pipeline A in another jenkins pipeline B
A little unclear if you want to invoke another pipeline script or job, so I answer both:
Pipeline scriptThe "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']]
Following solution works for me:
pipeline { agent { node { label 'master' customWorkspace "${env.JobPath}" } } stages { stage('Start') { steps { sh 'ls' } } stage ('Invoke_pipeline') { steps { build job: 'pipeline1', parameters: [ string(name: 'param1', value: "value1") ] } } stage('End') { steps { sh 'ls' } } }}
Adding link of the official documentation of "Pipeline: Build Step" here:https://jenkins.io/doc/pipeline/steps/pipeline-build-step/
To add to what @matias-snellingen said. If you have multiple functions, the return this
should be under the function that will be called in the main pipeline script. For example in :
def someMethod() { helperMethod1() helperMethod2()} return this def helperMethod1(){ //do stuff} def helperMethod2(){ //do stuff}
The someMethod()
is the one that will be called in the main pipeline script