SCM Polling

Polling makes Jenkins periodically check the repository and build only when it detects a change.

Syntaxtriggers { pollSCM('H/5 * * * *') }

SCM polling is an alternative to webhooks. Jenkins asks the repository, on a schedule, whether anything changed. If it did, a build starts; if not, nothing happens.

Polling vs webhooks

PollingWebhooks
Jenkins checks the repoRepo notifies Jenkins
Delayed (up to poll interval)Instant
Works behind a firewallNeeds Jenkins reachable

When polling helps

Use polling when your Git host cannot reach Jenkins directly — for example, a Jenkins server locked inside a private network.

Example

Example · bash
pipeline {
    agent any
    triggers {
        // Check the repo every 5 minutes; build only if it changed
        pollSCM('H/5 * * * *')
    }
    stages {
        stage('Build') {
            steps { sh 'make build' }
        }
    }
}

When to use it

  • A legacy CI workflow polls the SVN repository every 10 minutes because the SVN server cannot send push webhooks.
  • A team uses H/5 cron syntax so polling load is spread across agents rather than hitting the repo simultaneously.
  • SCM polling is used as a fallback trigger when the GitHub webhook fails intermittently due to firewall issues.

More examples

Poll SCM every 5 minutes

Configures Jenkins to poll the repository every five minutes and trigger a build only when changes are found.

Example · groovy
pipeline {
  agent any
  triggers {
    pollSCM('H/5 * * * *')  // every 5 minutes, hash-bucketed
  }
  stages {
    stage('Build') { steps { sh 'make all' } }
  }
}

Poll SCM on business hours only

Polls the repo roughly once an hour during working hours on weekdays, reducing off-hours server load.

Example · groovy
pipeline {
  agent any
  triggers {
    pollSCM('H 8-18 * * 1-5')  // hourly, Mon-Fri 8am-6pm
  }
  stages {
    stage('Build') { steps { sh 'mvn package' } }
  }
}

Combined poll and webhook trigger

Combines a GitHub webhook with a 30-minute poll as a safety net in case webhooks are missed.

Example · groovy
pipeline {
  agent any
  triggers {
    githubPush()          // primary: instant webhook
    pollSCM('H/30 * * * *')  // fallback: every 30 min
  }
  stages {
    stage('Build') { steps { sh 'npm test' } }
  }
}

Discussion

  • Be the first to comment on this lesson.