What if your builds could start themselves exactly when needed, without you doing anything?
Why Build triggers (poll SCM, webhook, timer) in Jenkins? - Purpose & Use Cases
Imagine you have a project where you need to build your code every time someone changes it. Without automation, you have to check the code repository yourself, then start the build manually each time.
This manual checking is slow and tiring. You might forget to build after changes, causing delays and bugs. It's also easy to make mistakes or miss updates, which breaks the flow of work.
Build triggers in Jenkins automatically start builds when something happens, like code changes or at set times. This means no more waiting or checking manually; the system does it for you instantly and reliably.
Check repo -> If changed, click 'Build' buttonSet trigger: poll SCM every 5 minutes or webhook on push
It lets your builds run automatically and instantly, keeping your project always up-to-date without lifting a finger.
A team pushes code to GitHub, and Jenkins starts the build immediately via webhook, so everyone sees the latest tested version fast.
Manual builds cause delays and errors.
Build triggers automate starting builds on events.
This keeps projects fresh and developers focused on coding.
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
