Software Development

What is the standard syntax to trigger a downstream Jenkins pipeline from an upstream script?

KI Asked by Kimberly Wright · 14-07-2024
0 upvotes 13,635 views 0 comments
The question

I am currently working on an Agile project where we need to separate our "Build" pipeline from our "Deployment" pipeline. I want Jenkins Pipeline B to automatically start Jenkins Pipeline A only after the unit tests in B have successfully passed. Should I use the build step syntax, and how do I pass specific parameters, like a version number or a branch name, from the first pipeline to the second one so they stay in sync? Is there a way to make Pipeline B wait for Pipeline A to finish before it marks itself as successful?

3 answers

0
PA
Answered on 15-07-2024

The most common and robust way to trigger one pipeline from another is by using the build step within your Jenkinsfile. The basic syntax is build 'Pipeline-A'. If you need to pass parameters, you include them in a list. For example: build job: 'Pipeline-A', parameters: [string(name: 'VERSION', value: '1.0.4')]. By default, this step is synchronous, meaning Pipeline B will pause and wait for Pipeline A to complete. If Pipeline A fails, Pipeline B will also be marked as a failure.

If you want Pipeline B to continue immediately without waiting for the result of Pipeline A, you can add the parameter wait: false. This is particularly useful for fire-and-forget tasks like cleanup scripts or notification triggers that don't impact the main build's success

0
ST
Answered on 17-07-2024

When you trigger Pipeline A, are you concerned about "cyclic dependencies" where Pipeline A might accidentally trigger Pipeline B back, or are you strictly looking for a linear flow? I ask because if you have many interconnected jobs, it might be better to look into the "Post-build Actions" in the UI rather than hardcoding the trigger inside the Jenkinsfile to keep the scripts cleaner.

BR 18-07-2024

Steven, I’m definitely looking for a linear flow. However, your point about the UI is interesting. If I use the Jenkinsfile build step as Patricia suggested, does that trigger still show up in the "Build Pipeline View" or the "Full Stage View" in the Jenkins dashboard? I want to make sure the team can visually see the link between the two jobs during the deployment process.

0
NA
Answered on 20-07-2024

Yes, Jenkins will show them as linked. In the sidebar of the job page, you will see "Downstream Projects" and "Upstream Projects" listed automatically once the build runs once.

KI 21-07-2024

Exactly, Nancy. Also, for Brian: If you use the Blue Ocean interface, the visualization of these linked pipelines is even better. I highly recommend using the propagate: true flag in your build step as well; it ensures that if the downstream job is aborted, that status is sent back to the upstream caller.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session