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
- You add a webhook in your repository settings pointing to your Jenkins URL.
- A developer pushes code.
- The Git host sends an HTTP request to Jenkins.
- Jenkins starts the matching job right away.
Example
# 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.
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.
# GitHub repo > Settings > Webhooks > Add webhook
# Payload URL:
http://jenkins.example.com/github-webhook/
# Content type: application/json
# Events: Just the push eventGeneric webhook trigger plugin
Uses the Generic Webhook Trigger plugin to accept webhook calls from any system that can send an HTTP POST.
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