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

How to get Pull request title as a Variable

tony.thomas
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!
August 18, 2020

Hey Team,

I would like to know how to get the Pull Request title as a Variable in Pipeline.

 

The below document gives a list of default variables, but can't find what I am looking for.

https://support.atlassian.com/bitbucket-cloud/docs/variables-in-pipelines/

 

2 answers

2 votes
ktomk
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 7, 2020

You can get the title of a pull-request via the API.

https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D

The BITBUCKET_PR_ID is available as environment variable if the pipeline is a pull-request pipeline.

tony.thomas
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!
September 7, 2020

I am getting the error 

Access denied. You must have write or admin access.

and I am the Admin of the Repo and Workspace.

 

Also is there a way I can get the Pull request title as a Variable just like BITBUCKET_PR_ID?

ktomk
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 8, 2020

@tony.thomas Yes, as written, you can get the PR title as output from the API. The output can be assigned to a variable (e.g. with utilities like jq or similar).

This requires using the API successfully first. Please check the existing Q&A and support resources for that incl. trouble-shooting. Some more references:

If it still does not work for you, please provide the example.

Example with the curl and the jq utilities (working API authentication with necessary access rights required):

 - |
BITBUCKET_PR_TITLE="$(\
curl ... -fsS -H 'Content-Type: application/json' \
"https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_FULL_NAME}"\
"/pullrequests/${BITBUCKET_PR_ID}" \
| jq -r '.title')" \
; test "$BITBUCKET_PR_TITLE"

 

Like Patrick Nelson likes this
0 votes
Marco Pellicciotta April 14, 2023

@tony.thomas , you can add on the curl command provided by @ktomk a header for bearer token:

 

--header 'Authorization: Bearer XXXXXX'

 

And replace XXXXXX with a token you generate on "Repository Settings > Access Tokens".

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events