How to trigger Jenkins builds automatically?
· Category: DevOps & CI/CD
Short answer
Trigger Jenkins builds automatically using SCM webhooks, cron schedules, or upstream job triggers. Webhooks provide the fastest feedback.
Steps
- Configure the SCM plugin with repository credentials.
- Add a webhook in the repository pointing to Jenkins.
- Enable
GitHub hook trigger for GITScm pollingor equivalent.
Example
pipeline {
agent any
triggers {
githubPush()
cron('H 2 * * *')
}
stages {
stage('Build') {
steps {
sh 'make'
}
}
}
}
Tips
- Use webhooks instead of polling to reduce load.
- Test webhooks with a manual delivery.
- Use parameterized triggers for flexibility.
Common issues
- Webhooks fail if Jenkins is not publicly accessible.
- Cron syntax differs from standard Unix cron.
- Branch indexing in Multibranch Pipelines can be slow.