Get a list of Bitbucket commits that are linked to Jira issue keys
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
This article provides ways to retrieve a list of Bitbucket commits that are associated to Jira issue keys.
Environment
Bitbucket Data Center with an application link to Jira Data Center or Jira Cloud
Solution
Get commits from REST API
To retrieve details on commits associated to a specific Jira issue key, use the Get changesets for issue key API endpoint.
For example:
curl -u <USERNAME> 'http://<bitbucket_URL>/rest/jira/latest/issues/ISSUE-1234/commits'
The output will show the commits associated to the Jira issue key specified in the endpoint path:
{
"size": 1,
"limit": 25,
"isLastPage": true,
"values": [
{
"fromCommit": {
"id": "88d22cd5bd2063b99b247d86d08544bfae7b203a",
"displayId": "88d22cd5bd2"
},
"toCommit": {
"id": "08bfa21fa0c84a10b52a5446871ae92a8594bfef",
"displayId": "08bfa21fa0c",
"author": {
"name": "John Doe",
"emailAddress": "johndoe@atlassian.com"
},
"authorTimestamp": 1744100864000,
"committer": {
"name": "John Doe",
"emailAddress": "johndoe@atlassian.com"
},
"committerTimestamp": 1744100864000,
"message": "ISSUE-1234 test issue",
"parents": [
{
"id": "88d22cd5bd2063b99b247d86d08544bfae7b203a",
"displayId": "88d22cd5bd2"
}
]
},
"changes": {
"size": 1,
"limit": 10,
"isLastPage": true,
"values": [
{
"contentId": "ccb69dfb891f1fecaaf1c93e3266c3620b194e92",
"fromContentId": "9bb87d71de26573ad53f7ec2d2d9a170e46b921f",
"path": {
"components": [
"test.txt"
],
"parent": "",
"name": "test.txt",
"extension": "txt",
"toString": "test.txt"
},
"executable": true,
"percentUnchanged": -1,
"type": "MODIFY",
"nodeType": "FILE",
"srcExecutable": true,
"links": {
"self": [
{
"href": "https://bitbucketdc/projects/PROJ1/repos/repo1/commits/08bfa21fa0c84a10b52a5446871ae92a8594bfef#test.txt"
}
]
},
"properties": {
"gitChangeType": "MODIFY"
}
}
],
"start": 0
},
"links": {
"self": [
{
"href": "https://bitbucketdc/projects/PROJ1/repos/repo1/commits/08bfa21fa0c84a10b52a5446871ae92a8594bfef#test.txt"
}
]
},
"repository": {
"slug": "repo1",
"id": 1,
"name": "repo1",
"hierarchyId": "fc728657fa639d2e87f9",
"scmId": "git",
"state": "AVAILABLE",
"statusMessage": "Available",
"forkable": true,
"project": {
"key": "PROJ1",
"id": 1,
"name": "Project 1",
"public": false,
"type": "NORMAL",
"links": {
"self": [
{
"href": "https://bitbucketdc/projects/PROJ1"
}
]
}
},
"public": false,
"archived": false,
"links": {
"clone": [
{
"href": "https://bitbucketdc/scm/proj1/repo1.git",
"name": "http"
},
{
"href": "ssh://git@localhost:5896/proj1/repo1.git",
"name": "ssh"
}
],
"self": [
{
"href": "https://bitbucketdc/projects/PROJ1/repos/repo1/browse"
}
]
}
}
}
],
"start": 0
}
Get commits based on database query
The Bitbucket database schema may change during version upgrades without notice.
To retrieve details on commits associated to a specific Jira issue key, use the query below and replace the <JIRA_ISSUE_KEY>
placeholder variable:
select proj.name as "Project Name"
, proj.project_key as "Project Key"
, repo.name as "Repository Name"
, repo.slug as "Repository Slug"
, attr.cs_id as "Changeset ID"
, attr.att_value as "Jira Issue Key"
from cs_attribute AS attr
inner join cs_repo_membership memb on attr.cs_id = memb.cs_id
inner join repository repo on memb.repository_id = repo.id
inner join project proj on repo.project_id = proj.id
and attr.att_name = 'jira-key'
and attr.att-value = '<JIRA_ISSUE_KEY>'
order by proj.name, repo.slug;
To retrieve details on commits associated to Jira issue keys, use the query below:
select proj.name as "Project Name"
, proj.project_key as "Project Key"
, repo.name as "Repository Name"
, repo.slug as "Repository Slug"
, attr.cs_id as "Changeset ID"
, attr.att_value as "Jira Issue Key"
from cs_attribute AS attr
inner join cs_repo_membership memb on attr.cs_id = memb.cs_id
inner join repository repo on memb.repository_id = repo.id
inner join project proj on repo.project_id = proj.id
and attr.att_name = 'jira-key'
order by proj.name, repo.slug, attr.att_value;
Was this helpful?