Milestone step for concurrency in Jenkins - Time & Space Complexity
When using the milestone step in Jenkins pipelines, it helps control how concurrent builds proceed.
We want to understand how the time to process builds changes as more builds run at once.
Analyze the time complexity of the following Jenkins pipeline snippet using milestone.
pipeline {
agent any
stages {
stage('Build') {
steps {
milestone 1
echo 'Building...'
}
}
stage('Test') {
steps {
milestone 2
echo 'Testing...'
}
}
}
}
This pipeline uses milestone steps to ensure only the latest build passes each milestone, cancelling older ones.
Look for repeated or concurrent operations that affect execution time.
- Primary operation: Multiple builds running concurrently, each hitting milestone steps.
- How many times: Number of concurrent builds trying to pass milestones.
As more builds run at the same time, the milestone step cancels older builds to keep only the latest.
| Concurrent Builds (n) | Approx. Active Builds After Milestone |
|---|---|
| 10 | 1 (latest build continues) |
| 100 | 1 (only newest build proceeds) |
| 1000 | 1 (milestone cancels all but latest) |
Pattern observation: Regardless of how many builds start, only one build passes each milestone, so execution time stays stable.
Time Complexity: O(1)
This means the time to pass a milestone does not grow with more concurrent builds because older builds are cancelled.
[X] Wrong: "More concurrent builds mean longer wait times at milestones because all builds wait their turn."
[OK] Correct: The milestone step cancels older builds, so only the newest build continues, keeping wait time constant.
Understanding how concurrency controls like milestone affect build time helps you design efficient pipelines and explain your reasoning clearly.
"What if we removed the milestone steps? How would the time complexity change with many concurrent builds?"