Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

how to use the bitbucket payload in jenkins

Ori Wiesel October 31, 2017

i'm trying to get the branch name that triggered the jenkins job via webhook, in my jenkins job.

but i can't figure how to use the bitbucket payload

2 answers

1 vote
Adrian K. March 13, 2018

It is an old question but since there is no answer yet, I will suggest the way I'm using.

Bitbucket payload is in JSON format. I'm reading the payload using jq. Jq is similar to sed for json files.

The payload comes to jenkins as BITBUCKET_PAYLOAD. In order to consume the data in jenkins job, I create a variable payload and further I trim the payload to show only specific branch impacted, as follow:

payload=${BITBUCKET_PAYLOAD}
payloadbranch=$(echo $payload | jq -r .push.changes[].new.name)

the "payloadbranch" is the variable to be used as branch in git path.

Anand Patil August 18, 2018

I tried the follow in my jenkins pipeline script

sh'''
payload=${BITBUCKET_PAYLOAD}
echo "payload="+ payload
'''

but the payload is empty. Also tried other parameters but nothing seems to work. This branch name should be made explicitly available to Jenkins for the Webhook plugin

 

Thanks

Anand

Antonius Golly September 5, 2019

The variable BITBUCKET_PAYLOAD is only available in Freestyle jobs. One workaround would be to create such a Freestyle job and trigger with that job your pipeline job as described here: https://stackoverflow.com/questions/41639641/access-bitbucket-payload-data-in-jenkins-pipeline-job

 

Alternatively, and this is my preferred way, you can create a middleware that parses the Bitbucket payload and calls the jenkins hook for parametrized builds as described here: https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build

0 votes
Tomas Bjerre February 7, 2018

You can consume the payload with Generic Webhook Trigger Plugin.

Muddassir Farooq February 19, 2018

but what if one is using bitbucket_webhook?

Deleted user May 5, 2021

or using the Bitbucket Sources Plugin with a multi-branch build configuration?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events