Webhooks

A webhook lets your Git host notify Jenkins the instant code is pushed, triggering an immediate build.

A webhook is a message your Git host (GitHub, GitLab, Bitbucket) sends to Jenkins the moment something happens — usually a push. This triggers a build instantly, with no polling delay.

How the flow works

  1. You add a webhook in your repository settings pointing to your Jenkins URL.
  2. A developer pushes code.
  3. The Git host sends an HTTP request to Jenkins.
  4. Jenkins starts the matching job right away.
A git push triggers a webhook that starts a Jenkins buildDevelopergit pushGit HostGitHub / GitLabJenkinswebhook receivedBuildHTTP POST
A push fires a webhook to Jenkins, which immediately starts the build.

Example

Example · bash
# In GitHub: Settings > Webhooks > Add webhook
#
#   Payload URL:  http://your-jenkins.com/github-webhook/
#   Content type: application/json
#   Events:       Just the push event
#
# In the pipeline job, enable:
#   'GitHub hook trigger for GITScm polling'

When to use it

  • A GitHub webhook pings Jenkins the moment a pull request is opened, triggering an immediate CI build for the PR branch.
  • A GitLab webhook triggers a Jenkins pipeline within seconds of a push to any branch, replacing a slow 5-minute SCM poll.
  • A webhook filters by event type so Jenkins only builds on push events, ignoring issue comments and wiki edits.

More examples

GitHub webhook Jenkinsfile trigger

Configures the pipeline to start automatically when GitHub sends a push webhook to Jenkins.

Example · groovy
pipeline {
  agent any
  triggers {
    githubPush()  // fires on GitHub push webhook
  }
  stages {
    stage('Build') { steps { sh 'npm ci && npm test' } }
  }
}

Webhook URL format for GitHub

Shows the exact GitHub webhook configuration values needed to point GitHub at a Jenkins instance.

Example · bash
# GitHub repo > Settings > Webhooks > Add webhook
# Payload URL:
http://jenkins.example.com/github-webhook/
# Content type: application/json
# Events: Just the push event

Generic webhook trigger plugin

Uses the Generic Webhook Trigger plugin to accept webhook calls from any system that can send an HTTP POST.

Example · groovy
pipeline {
  agent any
  triggers {
    GenericTrigger(
      causeString: 'Triggered by webhook',
      token: 'my-secret-token',
      tokenCredentialId: '',
      printContributedVariables: true,
      printPostContent: false
    )
  }
  stages {
    stage('Build') { steps { sh 'make' } }
  }
}

Discussion

  • Be the first to comment on this lesson.