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,700 points
119,565 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,620 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
• 59,230 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,460 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,460 points
3,298 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,460 points
3,410 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
• 59,230 points
78,652 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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,998 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
23,128 views
0 votes
2 answers

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

This is simple, use the following command: java ...READ MORE

answered Jul 4, 2018 in Jenkins by Sophie may
• 10,620 points
35,794 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP