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
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
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.
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.
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.
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.