Poll SCM configuration in Jenkins - Time & Space Complexity
We want to understand how the time taken by Jenkins changes when it checks for source code updates using Poll SCM.
Specifically, how does the checking time grow as the number of files or changes increases?
Analyze the time complexity of the following Jenkins Poll SCM configuration snippet.
pipeline {
agent any
triggers {
pollSCM('H/5 * * * *')
}
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
}
This code sets Jenkins to check the source code repository every 5 minutes for any changes before running the build.
Look at what Jenkins does repeatedly when polling SCM.
- Primary operation: Checking each file or commit in the source repository for changes.
- How many times: Every 5 minutes, Jenkins scans all relevant files or commits since the last check.
As the number of files or commits grows, Jenkins spends more time checking each one.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 files/commits | 10 checks |
| 100 files/commits | 100 checks |
| 1000 files/commits | 1000 checks |
Pattern observation: The checking time grows directly with the number of files or commits to scan.
Time Complexity: O(n)
This means the time Jenkins takes to poll grows in a straight line with the number of files or commits it checks.
[X] Wrong: "Polling SCM always takes the same time no matter how many files there are."
[OK] Correct: Jenkins must check each file or commit, so more files mean more work and longer polling time.
Understanding how Jenkins polling scales helps you explain build delays and plan efficient pipelines in real projects.
"What if Jenkins used webhooks instead of polling? How would the time complexity change?"