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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.