bitbucket webhook to jenkins with branch name

11,719

i've found a way to do it, it works for me. you need to use the bitbucket plugin: Bitbucket Plugin

then inside the job you need to specify the branch that will trigger the job after a push and check the marked checkbox: enter image description here

then on the bitbucket create a webhook with the following URL: http://:/bitbucket-hook/ Like so: enter image description here

then push something to this repository and that branch, and there you go! if you try to push to a different branch, the job won't be triiggered

Share:
11,719
Ori Wiesel
Author by

Ori Wiesel

Updated on June 08, 2022

Comments

  • Ori Wiesel
    Ori Wiesel almost 2 years

    i have a bitbucket repo that sends webhook to trigger jenkins job. bitbucket webhook

    http://:8080/buildByToken/buildWithParameters?job=webhook_me&token=t i want to send with the webhook the bitbucket branch name, so i search the web for the right way to use Environment variables on bit bucket and i've found this site: The way to use the variable, and the variable i need

    so i've edited the url with an "&branch=$BITBUCKET_BRANCH" at the end, but it won't work. The Jenkins job that was triggered and the attempt to echo the branch name

    any ideas what should i do in order to send the webhook with the branch name?

    *******EDIT*******

    i saw that there is something called Bitbucket event payload. which is a json that contains all of the details about the webhook: https://confluence.atlassian.com/bitbucket/event-payloads-740262817.html

    but i can't figure a way how to use it and pull it's data from jenkins.

    i think that, this is the way to solve this, but i don't know how to use it.

  • Ori Wiesel
    Ori Wiesel over 6 years
    correct me if i'm wrong, but there is no answer in your "Answer". it's something that i'm trying to do already, i'm looking for a way to pass the branch name. and that is what I ask in my question. do you know how can I pass the branch name from bitbucket to jenkins? Thanks!
  • soninob
    soninob over 3 years
    just for the record, it is also working when merging PR