Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

how to use the bitbucket payload in jenkins

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

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.

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

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

You can consume the payload with Generic Webhook Trigger Plugin.

but what if one is using bitbucket_webhook?

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

271 views 2 10
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