Pipeline stages and steps in Jenkins - Time & Space Complexity
We want to understand how the time to run a Jenkins pipeline changes as we add more stages and steps.
How does the total work grow when the pipeline gets bigger?
Analyze the time complexity of the following Jenkins pipeline snippet.
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Test') {
steps {
echo 'Testing...'
}
}
}
}
This pipeline has two stages, each with one step that prints a message.
Look for repeated actions in the pipeline.
- Primary operation: Executing each step inside every stage.
- How many times: Once per step, repeated for all stages.
As we add more stages and steps, the total work grows.
| Input Size (number of stages) | Approx. Operations (steps executed) |
|---|---|
| 10 | 10 steps (if 1 step per stage) |
| 100 | 100 steps |
| 1000 | 1000 steps |
Pattern observation: The total steps grow directly with the number of stages.
Time Complexity: O(n)
This means the time to run the pipeline grows in a straight line as you add more stages.
[X] Wrong: "Adding more stages won't affect total time much because they run fast."
[OK] Correct: Even if each step is quick, the total time adds up because all steps run one after another.
Understanding how pipeline time grows helps you design efficient build processes and explain your reasoning clearly in discussions.
"What if we run some stages in parallel? How would the time complexity change?"