Generate webHooks in Bitbucket Server via REST API for Pipeline Multibranch

Article ID:115000083932
2 minute readKnowledge base


  • I want to create webhooks in Bitbucket server to automatically trigger Multibranch or Bitbucket Team/Project jobs on changes


IMPORTANT: This article was created to workaround the issue JENKINS-38748. This issue has now been resolved. Indeed, since Bitbucket Branch Source 2.1.1 and Post Webhooks for Bitbucket 1.4.1 (Bitbucket add-on), the Bitbucket Branch Source provides the option to automatically register a webhook for your repository/ies. This is the recommended, quicker, easiest configuration. Follow the article How to Trigger Multibranch Jobs from Bitbucket Server for more details.

If you are really not able to upgrade, continue reading for a workaround.


A workaround is to use the REST API implemented by the Post Webhooks for Bitbucket. Indeed this add-on exposes a REST API that can be leveraged to create webhooks for your repository/projects in Bitbucket Server. For more information about this REST API, you can see the source code in nl.topicus.bitbucket.api.WebhookResource.

This article provides basic commands that can be used to automate the generation of webhooks until JENKINS-38748 is resolved.


Following variable are used in this article to make commands as generic as possible. Update them accordingly to match your environment:

  • $USER/$PASSWORD: Username/Password of a Bitbucket user with sufficient permission to create webhooks

  • $BITBUCKET_SERVER_URL: The URL of the Bitbucket Server

  • $PROJECT: The Bitbucket project name

  • $REPO: The Bitbucket repository name

  • $WEBHOOK_ID: The id of an existing Webhook in a Bitbucket repository

The webhook data when POSTing:

  • $TITLE: Title to give to the webhook

  • $ENABLED: true


  • $JENKINS_URL: The Jenkins URL

Example in the UI:

post webhooks for bitbucket

Get existing webhooks

Use the following command to get the existing webhooks of a project repository:

curl -u '$USER:$PASSWORD' -H "Content-Type: application/json" -X GET $BITBUCKET_SERVER_URL/rest/webhook/1.0/projects/$PROJECT/repos/$REPO/configurations

This will return the list of existing webhooks in a JSON Array.


curl -u 'user:password' -H "Content-Type: application/json" -X GET


[{"id":22,"title":"Jenkins Example","url":"","enabled":false}]

Create a webhook

Use the following command to create a new webhook for a repository:

curl -u '$USER:$PASSWORD' -H "Content-Type: application/json" -X PUT -d '{"title": "$TITLE", "url": "$JENKINS_URL/bitbucket-scmsource-hook/notify", "enabled": "$ENABLED"}' $BITBUCKET_SERVER_URL/rest/webhook/1.0/projects/$PROJECT/repos/$REPO/configurations

This will return the created webhook in a JSON Object.


curl -u 'user:password' -H "Content-Type: application/json" -X PUT -d '{"title": "", "url": "", "enabled": "true"}'



Update a webhook by ID

Use the following command to update an existing webhook of a repository:

curl -u '$USER:$PASSWORD' -H "Content-Type: application/json" -X POST -d '{"title": "$TITLE", "url": "$JENKINS_URL/bitbucket-scmsource-hook/notify", "enabled": "$ENABLED"}' $BITBUCKET_SERVER_URL/rest/webhook/1.0/projects/$PROJECT/repos/$REPO/configurations/$WEBHOOK_ID

This will return the updated webhook in a JSON Object.


curl -u 'user:password' -H "Content-Type: application/json" -X POST -d '{"title": "", "url": "", "enabled": "false"}'



Delete a webhook by ID

Use the following command to delete an existing webhook of a project repository:

curl -u '$USER:$PASSWORD' -H "Content-Type: application/json" -X DELETE $BITBUCKET_SERVER_URL/rest/webhook/1.0/projects/$PROJECT/repos/$REPO/configurations/$WEBHOOK_ID

This should return nothing unless there is an issue.


curl -u 'user:password' -H "Content-Type: application/json" -X DELETE