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

Get all linked Jira issues from a custom script in a pipeline

Vladimir Greenberg
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 27, 2023

Hello,

While developing features for my product I've been adding Jira issue keys to the Git commits. After a successful deployment via bitbucket-pipelines.yml I can see the linked issues in the "Deployments" section in my repository.

What I'm trying to achieve is to get a list of these issues as a part of my pipeline (I'm running a custom JS script). That script is making an API request to the:

https://api.bitbucket.org/rest/api/2.0/projects/${PROJECT_KEY}/repos/${REPOSITORY_SLUG}/pipelines/${PIPELINE_UUID}/issues

All of the variables are accessible via the environment variables of the pipeline itself. The authorization that is used is:

Authorization: 'Basic ${username:appPassword}' as Base64
Content-Type: 'application/json'

The response that I'm getting back is: 

"type": "error",
"error": {
"message": "Resource not found",
"detail": "There is no API hosted at this URL.\n\nFor information about our API's, please refer to the documentation at: https://developer.atlassian.com/bitbucket/api/2/reference/"
}

While the response is quite self-explanatory I'm struggling to find out the needed API in the documentation.

Thanks in advance.

1 answer

1 accepted

1 vote
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 4, 2023

Hi Vladimir and welcome to the community!

I'm afraid that we don't have an API endpoint for getting the Jira issues associated with a deployment.

We have a feature request in our issue tracker that you can vote for to express your interest:

You are more than welcome to leave feedback on that ticket and you can also add yourself as a watcher (by selecting the Start watching this issue link) if you'd like to get notified via email on updates. Implementation of new features is done as per our policy here and any updates will be posted in the feature request.

In the meantime, if you want to get this info during a Pipelines build, you would need to do some additional scripting.

If the pipelines build runs on a pull-requests definition, the variable BITBUCKET_PR_ID will be available during the build. You could get the PR's commits with the following API endpoint:

Then, you could parse the commit messages of the PR's commits for the referenced Jira issues.

If the build runs on branches, the process would be a bit more complicated. Please also note that it won't be foolproof. You could do the following:

  • Get all deployments for this repo and save them in a file
  • Filter deployments in this file to get only deployments in the current environment
  • Then, sort the deployments based on the created_on field, and get the last two deployments. The assumption here is that the last deployment is the current one and the second to last is the previous deployment. Please note that this assumption may be incorrect if you run frequent builds and another deployment was triggered after the current one.
  • For each of these two deployments, get the commit that triggered them
  • You can then use this endpoint to get all the commits between these two commits that triggered the deployments using the include and exclude keywords:
    https://developer.atlassian.com/cloud/bitbucket/rest/api-group-commits/#api-repositories-workspace-repo-slug-commits-get
  • Then, parse the commit messages to get the referenced Jira issues.

Kind regards,
Theodora

Suggest an answer

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

Atlassian Community Events