How to Configure Build Triggers in Jenkins for Automated Builds
In Jenkins, you configure build triggers by opening your job configuration and selecting the
Build Triggers section. Here, you can enable options like Poll SCM to check for source code changes, Build periodically to schedule builds, or Trigger builds remotely using tokens or webhooks for automation.Syntax
In Jenkins job configuration, build triggers are set under the Build Triggers section with these main options:
Poll SCM: Jenkins checks your source code repository at specified intervals.Build periodically: Jenkins runs builds on a fixed schedule using cron syntax.Trigger builds remotely: Allows builds to start via a URL with an authentication token.
Each option requires specific input formats, like cron expressions for scheduling or tokens for remote triggers.
text
Poll SCM: H/15 * * * * Build periodically: H 2 * * * Trigger builds remotely: Token = mySecretToken
Example
This example shows how to configure a Jenkins freestyle job to poll the Git repository every 15 minutes and trigger builds remotely using a token.
groovy
pipeline {
agent any
triggers {
pollSCM('H/15 * * * *')
// Remote trigger is configured in job settings, not pipeline syntax
}
stages {
stage('Build') {
steps {
echo 'Building project...'
}
}
}
}Output
[Pipeline] Start of Pipeline
[Pipeline] echo
Building project...
[Pipeline] End of Pipeline
Common Pitfalls
Common mistakes when configuring build triggers include:
- Using incorrect cron syntax causing triggers to never run.
- Not setting the SCM repository correctly, so
Poll SCMfinds no changes. - For remote triggers, forgetting to set or use the correct authentication token.
- Enabling multiple triggers that conflict or cause unexpected build frequency.
Always test your triggers after setup to confirm they work as expected.
text
Wrong cron example: Build periodically: 15 * * * * # Runs at minute 15 every hour Correct cron example: Build periodically: H/15 * * * * # Runs every 15 minutes with load balancing
Quick Reference
| Trigger Type | Description | Example Input |
|---|---|---|
| Poll SCM | Checks source code changes at intervals | H/15 * * * * |
| Build periodically | Runs builds on a schedule | H 2 * * * |
| Trigger builds remotely | Starts build via URL with token | Token: mySecretToken |
| GitHub hook trigger | Starts build on GitHub push events | Enable webhook in GitHub repo |
Key Takeaways
Configure build triggers in the Jenkins job under the Build Triggers section.
Use cron syntax for scheduling periodic builds or SCM polling.
Remote triggers require a secure token and URL setup.
Test triggers after setup to ensure builds start as expected.
Avoid conflicting triggers to prevent excessive builds.