Build steps execution in Jenkins - Time & Space Complexity
We want to understand how the time to run build steps changes as we add more steps.
How does the total work grow when the number of build steps increases?
Analyze the time complexity of the following Jenkins pipeline snippet.
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
for (int i = 0; i < stepsList.size(); i++) {
stepsList[i].execute()
}
}
}
}
}
}
This code runs each build step one after another from a list of steps.
Look for loops or repeated actions.
- Primary operation: Loop over all build steps to execute each one.
- How many times: Once for each build step in the list.
As the number of build steps grows, the total time grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 executions |
| 100 | 100 executions |
| 1000 | 1000 executions |
Pattern observation: The total work grows directly with the number of steps.
Time Complexity: O(n)
This means the time to finish all build steps grows in a straight line as you add more steps.
[X] Wrong: "Running more build steps won't affect total time much because they run fast."
[OK] Correct: Even if each step is fast, doing many steps adds up and total time grows with the number of steps.
Understanding how build steps add up helps you explain pipeline performance clearly and shows you can reason about process scaling.
"What if the build steps could run in parallel? How would the time complexity change?"