Configuring Webhooks in Bitbucket

Dumindu Yapa, MSc
3 min readOct 13, 2020

Webhooks provide a way to configure Bitbucket Server to make requests to your Jenkins server, whenever certain events occur.

When to use webhooks

  1. When someone pushes commits in a repository, you might require to start a build from a particular branch.
  2. When someone creates a pull request, you might want to display a notification in your app.

Configuration on Jenkins side...

  1. Go to your Jenkins server and click on Manage Jenkins

2. Click on the Configure Global Security

3. You need to uncheck “Prevent Cross Site Request Forgery exploits”

4. Go to the Authorization section and check Matrix-based security. Since the bitbucket payload coming under the anonymous user, you should give below necessary access to the anonymous user.

Overall - Read
Job - Build
Job - Read
Job - Workplace

Note: Giving these access using Matrix-based security is not a must. You can do the same with Project-based Matrix Authorization Strategy as well.

5. Now the authorization work has been done with the above changes.

  • Go to your job, you would like to configure webhook is for and choose configure.
  • Go to the triggers section, check on Trigger builds remotely & add a token.

Configuration on Bitbucket side…

  1. Go to the repository and click webhooks in repo settings.

2. Select Create webhook.

3. Set a specific name for a webhook, URL & the event you want to trigger.

Note :

Follow this pattern when you setting up the URL.
<jenkins job url>/build?token=<Token Name>

or

<jenkins job url>/buildWithParameters?token=<Token Name>

Ex : http://jenkins-url/job/test_application/build?token=iFBDOBhNhaxL4T9ass93HRXun2jF161Z

4. You can check the connectivity between Bitbucket and Jenkins by clicking the test connection. Status should be active. Save it and check the functionality.

Enjoy :)

--

--