Build triggers (poll SCM, webhook, timer) in Jenkins - Time & Space Complexity
We want to understand how the time Jenkins spends checking for changes grows as the number of triggers or polling intervals increase.
How does Jenkins' work change when using different build triggers like polling, webhooks, or timers?
Analyze the time complexity of this Jenkins pipeline snippet with polling and timer triggers.
pipeline {
triggers {
pollSCM('H/5 * * * *')
cron('H 0 * * *')
}
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
}
This pipeline triggers builds by checking the source code every 5 minutes and also runs once daily at midnight.
Look at what repeats over time in this setup.
- Primary operation: Polling the source code management (SCM) system every 5 minutes.
- How many times: About 12 times per hour for polling, plus 1 time daily for the timer.
As the number of polling intervals or timers increases, the checks Jenkins performs also increase.
| Input Size (number of triggers or intervals) | Approx. Operations (checks) |
|---|---|
| 10 (polls per hour) | 10 checks per hour |
| 100 (polls per hour) | 100 checks per hour |
| 1000 (polls per hour) | 1000 checks per hour |
Pattern observation: The number of checks grows directly with how often Jenkins polls or triggers builds.
Time Complexity: O(n)
This means the time Jenkins spends checking grows linearly with the number of polling intervals or timer triggers.
[X] Wrong: "Polling more often doesn't affect Jenkins' workload much because it's just a quick check."
[OK] Correct: Each poll requires Jenkins to connect and check the SCM, so more frequent polling increases the total work linearly.
Understanding how build triggers affect Jenkins' workload helps you design efficient pipelines and shows you can think about system performance in real projects.
"What if we replaced polling with only webhook triggers? How would the time complexity change?"