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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
or using the Bitbucket Sources Plugin with a multi-branch build configuration?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did anyone fine solution for this basically my webhook does trigger the job but i am unable to capture the payload in json format my issue is i want to capture the pr id and source branch
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to explain a bit, what does it mean "unable to capture the payload in json format" ? Do you get the payload at jenkins end? What echo $BITBUCKET_PAYLOAD will return. It seems it works only in a freestyle project, I haven't tested in other projects tho.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi @Adrian K_ my issue is my webhook trigger jenkins job once my pr is created now in jenkins job i want the data from webhook payload like what is my pr id for that particular trigger and what is my source branch and i want to echo those thing in jenkins console output my limitation is i amusing very old version of jenkins and i cannot install generic webhook plugin when i add string parameter in jenkins with name payload it gives empty value do i need to add anything at webhook level as well
webhook url: https://username:apitoken@jenkinsurl/job/jobname/buildWithParameters?
echo $payload gives empty
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.