0
0
JenkinsHow-ToBeginner · 3 min read

How to Use Poll SCM in Jenkins for Automated Builds

In Jenkins, use Poll SCM to schedule periodic checks of your source code repository for changes. Configure it by enabling Poll SCM in the job's Build Triggers section and setting a cron-style schedule to define how often Jenkins checks for updates.
📐

Syntax

The Poll SCM feature uses a cron-like syntax to schedule checks for source code changes. The syntax has five fields representing:

  • Minute (0-59)
  • Hour (0-23)
  • Day of month (1-31)
  • Month (1-12)
  • Day of week (0-7, where both 0 and 7 mean Sunday)

Example: H/15 * * * * means check every 15 minutes.

cron
H/15 * * * *
💻

Example

This example shows how to enable Poll SCM in a Jenkins freestyle job to check the Git repository every 10 minutes and trigger a build if changes are found.

text
1. Open Jenkins and go to your job configuration.
2. Scroll to the <strong>Build Triggers</strong> section.
3. Check the box for <strong>Poll SCM</strong>.
4. In the schedule field, enter: <code>H/10 * * * *</code>
5. Save the configuration.

Now Jenkins will check the repository every 10 minutes and start a build if there are new commits.
Output
Jenkins polls the SCM every 10 minutes and triggers builds only when changes are detected.
⚠️

Common Pitfalls

  • Using Poll SCM without SCM configured: Poll SCM requires a source code repository configured in the job; otherwise, it won't work.
  • Incorrect cron syntax: Mistakes in the schedule format can cause Jenkins to never poll or poll too frequently.
  • Expecting immediate builds: Poll SCM only triggers builds after the scheduled check finds changes; it does not watch in real-time.
  • Using Poll SCM with webhooks: If you use webhooks (like GitHub hooks), Poll SCM is often unnecessary and can cause redundant builds.
cron
Wrong schedule example:
H * * * * *  # Has 6 fields, but Poll SCM expects 5 fields

Right schedule example:
H/5 * * * *  # Correct 5-field cron syntax for every 5 minutes
📊

Quick Reference

FieldMeaningExample Values
MinuteMinute of the hour0, 15, 30, 45, H/10
HourHour of the day (0-23)0, 6, 12, 18, *
Day of MonthDay in the month1, 15, *
MonthMonth of the year1, 6, 12, *
Day of WeekDay of the week (0=Sun)0, 1, 5, 6, *

Key Takeaways

Enable Poll SCM in Jenkins job's Build Triggers to schedule source code checks.
Use correct 5-field cron syntax to define polling frequency.
Poll SCM triggers builds only when changes are detected during scheduled checks.
Avoid using Poll SCM with webhook triggers to prevent duplicate builds.
Ensure SCM repository is configured in the job for Poll SCM to work.