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?"
Practice
Solution
Step 1: Understand pipeline triggers
Pipeline triggers are used to start one job automatically after another job finishes.Step 2: Identify the purpose
This automation helps connect jobs without manual intervention.Final Answer:
To automatically start a job when another job finishes -> Option DQuick Check:
Pipeline triggers = automatic job start [OK]
- Thinking triggers run jobs manually
- Confusing triggers with log cleanup
- Believing triggers stop jobs
Build-App after the current pipeline completes successfully?Solution
Step 1: Recall Jenkins pipeline syntax for triggering jobs
The correct syntax uses thebuildstep with parameters likejob,propagate, andwait.Step 2: Match the correct syntax
build job: 'Build-App', propagate: true, wait: true matches the correct syntax exactly.Final Answer:
build job: 'Build-App', propagate: true, wait: true -> Option AQuick Check:
Correct build step syntax = build job: 'Build-App', propagate: true, wait: true [OK]
- Using incorrect keywords like 'trigger' or 'start'
- Missing required parameters
- Wrong order or syntax errors
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Trigger Test') {
steps {
build job: 'Test-Job', propagate: true, wait: true
}
}
}
}What happens when the 'Build' stage completes successfully?
Solution
Step 1: Understand the 'build' step with 'wait: true'
The 'build' step triggers another job and waits for it to complete before continuing.Step 2: Analyze the pipeline flow
After 'Build' stage, 'Test-Job' starts and Jenkins waits for it to finish before moving on.Final Answer:
The 'Test-Job' pipeline starts and Jenkins waits for it to finish -> Option BQuick Check:
'build' with wait=true means wait for downstream job [OK]
- Assuming downstream runs in parallel without waiting
- Thinking pipeline stops early
- Believing 'build' is invalid step
build job: 'Deploy-App', propagate: false, wait: true
What issue might occur if 'Deploy-App' fails?
Solution
Step 1: Understand 'propagate: false'
This setting means the failure of the downstream job does not fail the current pipeline.Step 2: Analyze failure behavior
If 'Deploy-App' fails, the current pipeline will continue running instead of stopping.Final Answer:
The current pipeline continues despite failure in 'Deploy-App' -> Option CQuick Check:
propagate false = ignore downstream failure [OK]
- Assuming pipeline stops on downstream failure
- Confusing propagate with wait
- Expecting syntax errors
Solution
Step 1: Ensure Job B triggers only on Job A success
Usingpropagate: truein Job A means failure in Job B will fail Job A, so Job B runs only if Job A succeeds.Step 2: Ensure Job C triggers regardless of Job B result
Usingpropagate: falseandwait: falsein Job B triggers Job C without waiting and ignores Job C's result.Final Answer:
Option A matches these requirements -> Option AQuick Check:
propagate true for success-only triggers, false for unconditional [OK]
- Using propagate false when success-only is needed
- Confusing wait true/false effects
- Triggering downstream jobs incorrectly
Ready to prove it?
Pass the test and this pattern moves unknown
