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

I want to read webhook payload in my jenkins

Nishant Tyagi September 2, 2024

HI all 
i have a webhook which triggers the Jenkins job once Pull request is created now on receiving end i need to read few details from that payload (PR id and source branch) and echo them in my Jenkins console 

i tried by creating the freestyle job which will have string parameter name payload but it when i echo it it always empty 

my webhook url is 

https://username:apitoken@jenkinsurl/job/jobname/buildWithParameters

i also tried with 

https://username:apitoken@jenkinsurl/job/jobname/buildWithParameters?payload=${BITBUCKET_PAYLOAD}

also with 

 

https://username:apitoken@jenkinsurl/job/jobname/build

any suggestion
note i cannot use any plugin as i am using old version of jenkins

2 answers

1 accepted

0 votes
Answer accepted
Nishant Tyagi September 16, 2024

Ok so this is how i kind of resolved it

1. you have to use generic webhook plugin (https://plugins.jenkins.io/generic-webhook-trigger) in case you are reading payload from event except push (means if your event which trigger webhook is anything except push event it will not work) only option is to use plugin

2. generic plugin config
Screenshot (499).png

 

3. if you event is push event then  just install bitbucket plugin it will give you option to trigger job whenever changes push to bitbucket add webhook url and now create one simple job (has to be freestyle) and  in scm section add your repo on which you created the webhook and in this job add option to trigger parametrized build chose option trigger predefined parameter
payload=${BITBUCKET_PAYLOAD}
now in your main job create string parameter with name payload now
when job one will trigger with webhook it will receive payload and then it will trigger your job (mainjob) and all value will be in string parameter i used this https://stackoverflow.com/questions/41639641/access-bitbucket-payload-data-in-jenkins-pipeline-job 

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 4, 2024

Hi and welcome to the community!

I think it's best to post this question on the Jenkins forum here:

https://community.jenkins.io/

We can offer assistance for issues or questions related to Bitbucket, but the way you read the payload after it is received from Jenkins is a Jenkins-related question.

On Bitbucket's side, you can enable logging for the webhook to check if the requests are successfully received by Jenkins. You can do this if you open the repo on Bitbucket's website, go to Repository settings > Webhooks, then select View requests for the Jenkins webhook you added. On the new page that opens, you can select Enable history.

Then, perform an event that triggers the webhook, and look at the page where you enabled history. Do you see the request listed there and what is the status code of the request?

If the request shows a status 200, then it is successfully received by your server and you can reach out to the Jenkins forum for guidance on how to read the payload. If you see an error, please let me know what the error is.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin Site Admin
TAGS
AUG Leaders

Atlassian Community Events