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

+2 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,370 points
19,342 views

2 answers to this question.

+2 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
• 9,940 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?
+1 vote

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
• 53,110 points

Related Questions In Jenkins

0 votes
2 answers
0 votes
2 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
• 53,110 points
4,817 views
0 votes
2 answers

how to execute a shell script post build step in Jenkins?

You could use the Post Build Task Plugin ...READ MORE

answered Jul 31, 2019 in Jenkins by Sirajul
• 53,110 points
10,040 views
+1 vote
1 answer

How to extract a substring of a string in a declarative pipeline code?

This would have been more easier using ...READ MORE

answered Aug 16, 2019 in Jenkins by Sirajul
• 53,110 points
6,171 views
+13 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,420 points
497 views
0 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
5,612 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
• 53,110 points
7,173 views