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?"
Practice
Solution
Step 1: Understand the purpose of poll SCM
poll SCM trigger makes Jenkins check the source code repository at set intervals for any changes.Step 2: Compare with other triggers
Webhook triggers build instantly on code push, timer triggers build at scheduled times, manual trigger requires user action.Final Answer:
poll SCM -> Option AQuick Check:
poll SCM = checks repo regularly [OK]
- Confusing webhook with poll SCM
- Thinking timer triggers check repo changes
- Assuming manual trigger is automatic
Solution
Step 1: Understand cron syntax
Cron format is 'minute hour day month weekday'. To run at midnight daily, minute=0 and hour=0.Step 2: Match the correct expression
0 0 * * * "0 0 * * *" means every day at 00:00 hours (midnight).Final Answer:
0 0 * * * -> Option BQuick Check:
Midnight daily cron = 0 0 * * * [OK]
- Mixing hour and minute fields
- Using wrong day or weekday values
- Confusing 12 PM with midnight
triggers {
pollSCM('H/15 * * * *')
}Solution
Step 1: Understand pollSCM with 'H/15 * * * *'
This means Jenkins checks the SCM every 15 minutes for changes.Step 2: Determine when build triggers
Build triggers only if changes are detected during these checks, not every 15 minutes automatically.Final Answer:
Build runs only if SCM changes detected every 15 minutes -> Option AQuick Check:
pollSCM triggers on changes every 15 mins [OK]
- Assuming build runs every 15 minutes regardless
- Confusing pollSCM with timer trigger
- Thinking webhook triggers are involved here
triggers {
pollSCM('H/5 * * * *')
}
What is the most likely cause?Solution
Step 1: Check pollSCM prerequisites
pollSCM requires SCM polling enabled globally in Jenkins settings.Step 2: Validate other options
Syntax 'H/5 * * * *' is valid; webhook is separate trigger; no conflict with timer here.Final Answer:
SCM polling is disabled in Jenkins global settings -> Option DQuick Check:
pollSCM needs global SCM polling enabled [OK]
- Assuming cron syntax is wrong
- Thinking webhook is mandatory for pollSCM
- Believing timer conflicts cause failure
Solution
Step 1: Understand requirements
Build at 6 AM weekdays and immediately on GitHub push means two triggers needed: timer and webhook.Step 2: Evaluate options
Use timer trigger '0 6 * * 1-5' and configure GitHub webhook combines timer for scheduled build and webhook for instant build on push, fulfilling both needs.Final Answer:
Use timer trigger '0 6 * * 1-5' and configure GitHub webhook -> Option CQuick Check:
Timer + webhook = scheduled + instant builds [OK]
- Using only pollSCM misses instant build
- Using webhook alone misses scheduled build
- Polling every minute is inefficient
Ready to prove it?
Pass the test and this pattern moves unknown
