Using Jenkins Generic Webhook Trigger to Capture Bitbucket Pull Request Events
This guide explains how to configure a Bitbucket webhook and a standard Jenkins job with the generic‑webhook‑trigger plugin to automatically receive pull‑request events, extract the PR ID, and trigger downstream actions without relying on a multi‑branch pipeline job.
This article explains how to use the Jenkins generic-webhook-trigger plugin to capture Bitbucket repository events such as Pull Request IDs.
While a Multi‑branch Pipeline job can expose PR information via environment variables, creating such a job often requires cloning the repository and is not the most efficient approach.
Instead, you can set up a regular Jenkins job to receive Bitbucket webhook events. First, create a Bitbucket webhook with a name (e.g., test-demo ) and a URL like http://JENKINS_URL/generic-webhook-trigger/invoke?token=test-demo . The webhook can be configured under the “Webhooks” or “Post Webhooks” section.
Next, configure the Jenkins job to use the generic‑webhook‑trigger plugin, specifying the same token ( test-demo ) so the webhook payload is accepted. In the pipeline script, add a line such as echo pr_id is ${pr_id} to output the received Pull Request ID.
To test, create a Pull Request in the monitored Bitbucket repository. The webhook triggers the Jenkins job, which runs the pipeline and prints the PR ID in the console log, confirming that the event data was successfully captured.
With the PR ID available, you can invoke additional scripts or services—such as calling the Bitbucket REST API—to retrieve detailed PR information, analyze changed files, link Jira tickets, or automate review and regression testing.
DevOps Engineer
DevOps engineer, Pythonista and FOSS contributor. Created cpp-linter, commit-check, etc.; contributed to PyPA.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.