How to get a mapping of Jira issue and user who resolved the issue ?
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles 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
The purpose of this article is to describe a way to write a script that will return the mapping of issue-key and user who resolved that issue:
Environment
Jira Server/Data Center on any version from 9.0.0.
Solution
The mapping "Issue Key/Jira user" can be obtained by using the expand=changelog parameter from the the REST API getIssue.
The example below shows a snippet of the information obtained when using this parameter:
<base-url>/rest/api/2/issue/<issue-key>?expand=changelog"
{
"id": "10305",
"author": {
"self": "<base-url>/rest/api/2/user?username=testUser1",
"name": "testUser1",
"key": "JIRAUSER10100",
"emailAddress": "testUser1@test.com",
"avatarUrls": {
"48x48": "https://www.gravatar.com/avatar/94fba03762323f286d7c3ca9e001c541?d=mm&s=48",
"24x24": "https://www.gravatar.com/avatar/94fba03762323f286d7c3ca9e001c541?d=mm&s=24",
"16x16": "https://www.gravatar.com/avatar/94fba03762323f286d7c3ca9e001c541?d=mm&s=16",
"32x32": "https://www.gravatar.com/avatar/94fba03762323f286d7c3ca9e001c541?d=mm&s=32"
},
"displayName": "testUser1",
"active": true,
"timeZone": "Etc/UTC"
},
"created": "2024-09-12T09:21:41.323+0000",
"items": [
{
"field": "resolution",
"fieldtype": "jira",
"from": null,
"fromString": null,
"to": "10000",
"toString": "Done"
},
{
"field": "status",
"fieldtype": "jira",
"from": "3",
"fromString": "In Progress",
"to": "10001",
"toString": "Done"
}
]
}
To get the name of the user who resolved the issue from the example above, you will need to:
- first look for the change made to the resolution field (in the Items → Field key)
- then look for the displayName key (which is testUser1 in the example above)
Suggested Script
The steps outlined on this article are provided AS-IS. This means we've had reports of them working for some customers — under certain circumstances — yet are not officially supported, nor can we guarantee they'll work for your specific scenario.
You may follow through and validate them on your own non-prod environments prior to production or fall back to supported alternatives if they don't work out.
We also invite you to reach out to our Community for matters that fall beyond Atlassian's scope of support!
- The script provided below will process multiple issues
- The variable issuekeys_csv in the script is having list of issue-key, comma separated
To run this script jq utility should be installed in that host OS:
#!/bin/bash # csv of Issue Keys issuekeys_csv="P1-1,P1-2,P1-3,P1-4" IFS=',' read -r -a issuekeys <<< "$issuekeys_csv" # Jira API base URL. Here replace <base-url> with Jira base-url. base_url="<base-url>/rest/api/2/issue" # Your Jira credentials (username and API token or password) username="user1" password="password1" # Iterate over each issue key in the array for issuekey in "${issuekeys[@]}"; do # Construct the URL for the current issue url="$base_url/$issuekey?expand=changelog" # Fetch the issue JSON using curl with basic authentication issue_json=$(curl -s -u "$username:$password" "$url") # Use jq to find the author of the change where resolution is set to "Done". user=$(echo "$issue_json"| jq -r '[.changelog.histories[] | select(.items[] | select(.field == "resolution" and .toString == "Done")) | .author.displayName] | join(" ")') # Output the result echo "$issuekey:$user" # Sleep for 300ms before the next request sleep 0.3 done $ ./resolvedByUser.sh P1-1:testUser2 P1-2:testUser1 P1-3:testUser3 P1-4:testUser4
- Please consider this just an example. It is not production ready, user would have to modify it as per requirement.