Steps within stages in Jenkins - Time & Space Complexity
We want to understand how the time to run a Jenkins pipeline changes when we add more steps inside stages.
How does adding steps affect the total work Jenkins does?
Analyze the time complexity of the following Jenkins pipeline snippet.
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Step 1'
echo 'Step 2'
echo 'Step 3'
}
}
}
}
This pipeline has one stage with three steps that run one after another.
Look for repeated actions inside the pipeline.
- Primary operation: Each step inside the stage runs once in order.
- How many times: The number of steps determines how many operations run.
As you add more steps, the total work grows directly with the number of steps.
| Input Size (n = steps) | Approx. Operations |
|---|---|
| 3 | 3 steps run |
| 10 | 10 steps run |
| 100 | 100 steps run |
Pattern observation: Doubling the steps doubles the work; it grows in a straight line.
Time Complexity: O(n)
This means the total time grows directly with the number of steps you add inside the stage.
[X] Wrong: "Adding more steps inside a stage does not affect the total time much because they run fast."
[OK] Correct: Even if each step is fast, adding many steps adds up and increases total time linearly.
Understanding how steps add up helps you explain pipeline performance clearly and shows you grasp how Jenkins runs tasks.
"What if the steps inside the stage ran in parallel instead of one after another? How would the time complexity change?"