Best way of triggering Jenkins jobs from Bitbucket Server (hooks)

449 views
Skip to first unread message

Torsten Reinhard

unread,
Sep 18, 2019, 5:34:58 AM9/18/19
to Jenkins Users
Hi all,

we are using Bitbucket Server (5.8.2) to manage our Git repositories.It has several options for setting up "hooks":
  • Hooks
  • Webhooks
  • Post Webhooks

In Jenkins we are using different job types:
  • the Multibranch Plugin
  • "normal" Pipeline jobs
  • "old-school" Freestyle Jobs
  • Maven-jobs
  • ...

What is the recommended (and hopefully easiest) way of enabling push notifications for all of those job types? I´m currently confused because there seems to be lots of different,sometimes outdated ways.

I would like to have the job(s) self-registering in Bitbucket when started manually - and that´s it.
All of our jobs are generated using the Job-DSL - and I dont wont to add and maintain the triggers in Bitbucket manually....

Noteworthy, the hooks should support the notificatoin of multiple Jenkins, of course (Productive, Test-Jenkins, .......) - for the same repo.

Thanx for guiding me through the configuration options

Torsten

Torsten Reinhard

unread,
Sep 18, 2019, 5:57:35 AM9/18/19
to Jenkins Users
I found this post already:

But due to some limitations, we are restricted to version 4.0.0 of the plugin on Bitbucket side - and cannot upgrade, so multiple Jenkins instances are not supported :-(

Carel Combrink

unread,
Sep 18, 2019, 11:48:06 AM9/18/19
to jenkins...@googlegroups.com
Hi,

I solved this yesterday for our setup.
If you don't have at least Bitbucket server 5.4 then this guide is not relevant  to you, see below. 

This is the gist 
  1.  Install the Bitbucket Branch Source plugin in Jenkins.
  2. Go to Manage Jenkins → Configure System. Scroll down to Bitbucket Endpoints.
  3. Click the Add button and select Bitbucket Server from the dropdown.
  4. Enter the name and URL for your endpoint.
  5. Check the "Manage hooks" checkbox
  6. Enter credentials that have "Admin" access on the Bitbucket Repository
    1. The user adds the hooks, thus needs admin
    2. For our setup I could give the Jenkins user admin rights for just the moment and revoked the rights after everything was set up and working. 
  7. Select the "Webhook implementation to use" 
    1. Select "Native"
    2. From the Jenkins info: "The native Webhook implementation available since Bitbucket Server 5.4." (thus no plugin needed)
  8. Set up the Jenkins Project
    1. We use "Bitbucket Organization Folder"
  9. Let Jenkins scan the project
  10. It should add the hooks under "Webhooks" in Bitbucket
    1. Once this is done you can revoke admin rights for the Jenkins user on BB for the repos
I am no expert but hope this helps.

Regards,

Torsten Reinhard

unread,
Sep 23, 2019, 2:30:26 AM9/23/19
to Jenkins Users
Hi,

for the Bitbucket Branch Source plugin it´s straight-forward - but in Bitbucket Server we have an old plugin (version 4.0.0) which is not supporting multiple Jenkins right now :-(
How would you register other (legacy) jobs, like Freestyle jobs or standard pipeline jobs? I haven´t found any automated hook-management in other than the Branch Source plugin until now?
The workarounds to that is legacy code, that uses the Bitbucket REST API to register jobs and their hooks....

Thx anyway,

Torsten

Reply all
Reply to author
Forward
0 new messages