Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get pull request id by commit hash

Lubomir Stoimchev
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 10, 2020

Hello,

Do anyone know how to get the pull request ID based on the commit's hash?

I'm triggering a jenkins job via http webhook. Once the job ends, if there is a problem I want to mark the PR as "needs work".

I've found a working API call (https://docs.atlassian.com/bitbucket-server/rest/6.0.2/bitbucket-rest.html#idp288) but I need to provide the PR ID.

Unfortunately the HTTP webhook plugin does not provide such property.

2 answers

0 votes
Aaron Mailhot
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 30, 2023

I realize it is not quite the answer you requested, but do you use or have you considered using multi-branch pipelines in Jenkins? With multi-branch pipelines, you are automatically hooked into BitBucket such that the failed build will cause the failure to be seen on the BitBucket PR and you can readily have your merge checks 'block' on that failure as in users have to get the job passing before the PR can be merged.

You can also then do more custom behavior if desired, including getting the PR ID from the Jenkins CHANGE_ID and BRANCH_NAME environment variables and sending info to that API endpoint if the built-in hooks are insufficient for your needs.

Sayed Imran
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 13, 2024

I really don't see any env variable CHANGE_ID when the job runs, I checked by printing all the env variables available during the build.

0 votes
Oweis Al-Agtash November 16, 2020

Hello, 

Have you found a way so far? 

I also need PR ID for a similar use case.

 

Many Thanks in advance!

Sayed Imran
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 13, 2024

Any update on this on how to get the PR ID ?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events