How to trigger a Jenkins pipeline A in another Jenkins pipeline B

+5 votes
I’ve created two Jenkins pipeline, let’s say pipelineA and pipelineB. I want to invoke pipelineA in pipelineB. How can this be done?
Jul 5, 2018 in Jenkins by Tyrion anex
• 8,650 points
40,779 views

3 answers to this question.

+4 votes

You can run the following code, its an example of running pipelineA in pipeline.

Make sure you’ve created a ‘pipelineA’ before running this code.

pipeline {
agent
    {
        node {
                label 'master'
                customWorkspace "${env.JobPath}"
              }
    }
    stages 
    {
        stage('Start') {
            steps {
                echo 'Hello'
            }
        }
        stage ('Invoke_pipelineA') {
            steps {
                build job: 'pipelineA', parameters: [
                string(name: 'param1', value: "value1")
                ]
            }
        }
        stage('End') {
            steps {
                echo 'Bye'
            }
        }
    }
}
answered Jul 5, 2018 by Sophie may
• 10,530 points
I think the question was to trigger a pipeline from another jenkins.
I think what @Tyrion meant is that he has two pipelines on same Jenkins and would like to invoke pipeline in pipelineB
Can we call the downstream job in other Jenkins environments ?
You can definitely use the downstream approach. But the thing with downstream is that you can invoke PipelineB only after PipelineA is executed.

What if I want to execute PipelineB somewhere in between the execution of PipelineA?
+2 votes

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']]
answered Jul 31, 2019 by Sirajul
• 58,990 points
0 votes

Hi,

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. This configuration allows you to trigger another exciting job on a different CM (remote). The downstream job name part will autocomplete.

answered Dec 14, 2020 by MD
• 95,060 points

Related Questions In Jenkins

0 votes
2 answers
0 votes
1 answer

How to trigger a build on commit to branch in declarative pipeline

Hi@Madhura, You can use triggers keyword in your ...READ MORE

answered Jul 9, 2020 in Jenkins by MD
• 95,060 points
563 views
0 votes
1 answer

How to setup which trigger email notification to email id's in Jenkins pipeline script at every stage?

Hi@Shashi, You need to install some plugins in ...READ MORE

answered Sep 18, 2020 in Jenkins by MD
• 95,060 points
605 views
+1 vote
3 answers

How to auto build a job in jenkins if there is any change in code on Github repository?

To automatically run build on code commit, follow ...READ MORE

answered Jul 31, 2019 in Jenkins by Sirajul
• 58,990 points
18,421 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
950 views
+2 votes
1 answer
0 votes
3 answers

How to get the Maven Version of a project in Jenkins?

Here is a snippet from our Jenkins ...READ MORE

answered Oct 4, 2019 in Jenkins by Petr Doležal
9,785 views
0 votes
2 answers

How to start Jenkins on a different port rather than 8080?

In case you want to change the ...READ MORE

answered Jul 31, 2019 in Jenkins by Sirajul
• 58,990 points
14,675 views