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).
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 https://confluence.atlassian.com/bitbucketserver/event-payload-938025882.html 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 = $.repository.project.name
event_key (repo:refs_changed) = $.eventKey
date = $.date
commit_id = $.changes.toHash
branch_name = $.changes.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.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.
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"
Hi Community! The submissions are in (and listed below) for the 🍻🍂Apptoberfest🍂🍻 Demo Competition and it’s time for you to place your votes for the best: Analytics & reporting app demo ...
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