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

  1. Configure the SCM plugin with repository credentials.
  2. Add a webhook in the repository pointing to Jenkins.
  3. Enable GitHub hook trigger for GITScm polling or 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.