Running Jenkins after each change – Poll SCM

Poll SCM is a feature in Jenkins that periodically checks the source code management (SCM) system (such as Git, Subversion, etc.) for changes. When enabled, Jenkins polls the repository at a specified frequency and triggers a build if any changes or new commits are detected since the last build.

Syntax
H/15 * * * *

Would last have run at Sunday, September 8, 2024 at 11:56:45 AM Coordinated Universal Time; would next run at Sunday, September 8, 2024 at 12:11:45 PM Coordinated Universal Time.

It means it will run every 15 minutes.

Be careful here!
Syntax: H/1 * * * * does not mean that it runs every minute. But every hour.
If you want to run the job every 1 minute you need to use the following syntax: * * * * *

How Poll SCM Works:
Jenkins does not run a build every time it polls the repository, but only when it detects a change.
You specify a polling schedule using cron-like syntax, similar to how you schedule periodic builds (e.g., H/15 * * * * would check every 15 minutes).
If changes are found (new commits, modified files, etc.), Jenkins triggers a build for that project.

Polling is less resource-intensive compared to triggering a build on every commit or using webhooks, but can still cause unnecessary load if polling too frequently.

Why to use it?
– Poll SCM is useful for projects where you don’t need immediate build triggers, but you still want Jenkins to react when there are code changes.
– Similar to periodic builds, you define how often Jenkins should poll using cron expressions.
– Polling does not trigger a build unless there are actual changes detected in the repository.

Example Usage:
Open the configuration for a job (Configuration -> Build triggers -> Poll SCM),
Check the “Poll SCM” box under “Build Triggers,
“Define the schedule for polling using cron syntax (e.g., H/15 * * * * to check every 15 minutes).

This allows Jenkins to monitor your repository for changes and only build when necessary.

Related posts