Why patterns solve common problems in Jenkins - Performance Analysis
We want to see how using patterns in Jenkins pipelines affects how long tasks take as they grow bigger.
How does the time needed change when we repeat common steps in a pattern?
Analyze the time complexity of the following Jenkins pipeline snippet using a pattern.
pipeline {
agent any
stages {
stage('Build Multiple Projects') {
steps {
script {
def projects = ['projA', 'projB', 'projC']
projects.each { project ->
build job: project
}
}
}
}
}
}
This pipeline runs a build job for each project in a list, using a pattern to repeat the build step.
Look for repeated actions that take time.
- Primary operation: Running the build job for each project.
- How many times: Once for each project in the list.
As the number of projects grows, the total build steps grow too.
| Input Size (n) | Approx. Operations |
|---|---|
| 3 | 3 build jobs |
| 10 | 10 build jobs |
| 100 | 100 build jobs |
Pattern observation: The time grows directly with the number of projects.
Time Complexity: O(n)
This means the total time grows in a straight line as you add more projects to build.
[X] Wrong: "Using a pattern makes the pipeline run faster regardless of input size."
[OK] Correct: Patterns organize repeated steps but do not reduce the total work needed for each item.
Understanding how repeating steps affect time helps you explain pipeline efficiency clearly and confidently.
"What if we ran all build jobs in parallel instead of one after another? How would the time complexity change?"