Search code examples
jenkinsjenkins-pipelinejenkins-2

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.


Solution

  • 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/