Why knowing alternatives matters in Jenkins - Performance Analysis
Knowing different ways to do a task helps us see how fast or slow each way is.
We want to find out how the choice of method changes the work needed as tasks grow.
Analyze the time complexity of the following Jenkins pipeline steps.
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
for (int i = 0; i < params.BUILD_COUNT; i++) {
echo "Building project #${i + 1}"
}
}
}
}
}
}
This code runs a build step multiple times based on a parameter.
Look for repeated actions that take time.
- Primary operation: The for-loop that runs the build step.
- How many times: It runs as many times as the BUILD_COUNT parameter.
As BUILD_COUNT grows, the number of build steps grows the same way.
| Input Size (BUILD_COUNT) | Approx. Operations |
|---|---|
| 10 | 10 build steps |
| 100 | 100 build steps |
| 1000 | 1000 build steps |
Pattern observation: The work grows directly with the number of builds requested.
Time Complexity: O(n)
This means if you double the number of builds, the total work roughly doubles too.
[X] Wrong: "Running builds in a loop always takes the same time no matter how many builds."
[OK] Correct: Each build adds more work, so more builds mean more time spent.
Understanding how different ways to run tasks affect time helps you explain your choices clearly in real projects.
"What if we replaced the loop with parallel build steps? How would the time complexity change?"