Pipeline triggers and upstream/downstream in Jenkins - Time & Space Complexity
When Jenkins pipelines trigger other pipelines, the total work depends on how many pipelines run and how they connect.
We want to know how the number of triggered pipelines affects the total execution steps.
Analyze the time complexity of the following Jenkins pipeline trigger setup.
pipeline {
agent any
stages {
stage('Build') {
steps {
build job: 'DownstreamJob'
}
}
}
}
// DownstreamJob triggers UpstreamJob similarly
This pipeline triggers a downstream job, which may trigger upstream jobs, forming a chain of triggers.
Look for repeated pipeline triggers that cause more jobs to run.
- Primary operation: Triggering another pipeline job.
- How many times: Once per pipeline in the chain, potentially cascading through multiple jobs.
Each triggered pipeline adds its own execution steps, increasing total work.
| Number of Triggered Pipelines (n) | Approx. Total Pipeline Runs |
|---|---|
| 2 | 2 pipelines run sequentially |
| 5 | 5 pipelines run one after another |
| 10 | 10 pipelines run in a chain |
Pattern observation: Total execution grows linearly with the number of triggered pipelines.
Time Complexity: O(n)
This means the total work grows directly in proportion to how many pipelines are triggered in sequence.
[X] Wrong: "Triggering pipelines is instant and does not add to total execution time."
[OK] Correct: Each triggered pipeline runs its own steps, so total time adds up with each trigger.
Understanding how pipeline triggers add up helps you design efficient CI/CD flows and explain your reasoning clearly in discussions.
"What if multiple downstream pipelines are triggered in parallel instead of sequentially? How would the time complexity change?"