Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Jenkins builds kicked off by Bitbucket

Has anyone been able to use a Webhook to kick off Jenkins builds in the latest version of BB Server (6.1.1) WITHOUT installing any plugins? It appears all required functionality is now built in (using a Webhook).



3 answers

1 accepted

1 vote
Answer accepted

Assuming you mean without installing any Bitbucket Server plugins, I have found a decent way to trigger Jenkins builds using the standard Bitbucket Server webhooks.

I use the Jenkins plugin Generic Webhook Trigger.

The Jenkins plugin exposes a URL endpoint that you can configure in the Bitbucket webhook settings. E.g. http://my-jenkins-server:8080/generic-webhook-trigger/invoke?token=<unique-token>

Bitbucket Server sends a webhook payload as JSON. Use to determine the payload data you want to extract. In the Jenkins configuration section for the Generic Webhook Trigger plugin, add post content parameters to extract data from the payload using expressions. For example, $.actor.displayName will get the display name of the person that caused the webhook to trigger (such as the person who pushed a commit or opened a pull request).

Here are some example expressions for common variables during a Push event:

repo_slug = $.repository.slug

project_name = $

event_key (repo:refs_changed) = $.eventKey

date = $.date

commit_id = $.changes[0].toHash

branch_name = $.changes[0].ref.displayId

actor_email = $.actor.emailAddress

actor_display_name = $.actor.displayName

Otherwise, multiple webhooks can be configured in Bitbucket Server to be able to trigger certain jobs for certain events. For example, you may want to have a webhook that triggers a master Jenkins job when a commit is pushed to your master branch or a pull request job that triggers whenever someone opens a new pull request in your repository.In the same section is an item called a "token." This token allows the URL endpoint to only trigger jobs that contain that same token. For example, http://jenkins:8080/generic-webhook-trigger/invoke?token=my-unique-job-token will only trigger jobs that use a token of "my-unique-job-token. These tokens can be used to trigger a single job or groups of jobs through a single webhook. The token is optional, so you can use the URL as http://jenkins:8080/generic-webhook-trigger/invoke to trigger all jobs that do not have a token set.

There are many other features of the Generic Webhook Trigger plugin that is useful for Bitbucket Server webhooks, but I will not go into detail here.

The importance of this plugin is that these extracted parameters can be used elsewhere in the Jenkins configuration, most notably the Git plugin. Use the parameter values by using $parameter_name in places where you want the build to change depending on the webhook payload. For example, if I set up a parameter BB_SERVER_BRANCH = $.changes[0].ref.displayId, I could set the Git plugin "Branches to build" to $BB_SERVER_BRANCH, causing my Jenkins job to choose to build the branch that caused the webhook event.

Fantastic information. I used this to get branch builds and feedback to BB setup for a pipeline. PR change pushed >  triggers pipeline > fail/success status sent back to BB granting permission to merge changes.


Very nice answer.

So much details.

I have been looking some of the information for some time.

I will see if it works in my jenkins pipeline.

It gives me lots to work with.

I would have been even happier if there was a documentation link to "common variables during a Push event"



Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

Marketplace Partner Spotlight: AppLiger

This month the spotlight is on AppLiger. We caught up with Pavel Pavlovsky, CEO and Product Manager, to learn how the company started and what fuels the team's creativity.    Atlassian:...

389 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you