Find Jira issues where attachments size is greater than a specific size
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
Many times we come across scenarios wherein we want to use JQL to find the issues with regard to attachments which meet certain criteria or to see the details of attachments on issues.
As such the JQL can only assist with finding issues with attachments or no attachments. We can achieve this by using a combination of APIs and JSON Query.
In the article, we will be fetching the details of all the attachments in a site and also customize it further to fetch issues with attachments greater than 2MB.
More details on Jira APIs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/
More on JQ: https://www.linode.com/docs/guides/using-jq-to-process-json-on-the-command-line/
This method is applied to MacOS.
Solution
First install a JSON Query package on machine. As this is applicable to MAC, therefore HOMEBREW will be required for installing the JQ package.
HOMEBREW is a package that basically simplifies the process of installing other packages on your MAC. More details on HOMEBREW are here: https://brew.sh/
You can check if it's already installed by checking the version for HOMEBREW on your system:
1
2
brew -v
Once it's confirmed that HOMEBREW is installed on your system, you just need to install the JQ package via the terminal:
1
brew install jq
Once JQ is installed you can use the below to find the Attachment details or filter issues on the basis of Attachment details.
To fetch size, name and issue details of the attachments.
1
2
3
4
5
for i in $(seq 0 50 50)
do
curl -s --request GET --url "https://<domain>.atlassian.net/rest/api/3/search?jql=attachments%20is%20not%20empty&fields=attachment&maxResults=50&startAt=$i" --header 'Accept: application/json' --user '<email address>:<Token>' | jq '.issues[] | { key: .key, attachment: .fields.attachment[] } | "\(.key) => \(.attachment.filename) => \(.attachment.size)Bytes"'
done
To fetch issues with attachment size of greater than 2MB.
1
2
3
4
for i in $(seq 0 50 50)
do
curl -s --request GET --url "https://<domain>.atlassian.net/rest/api/3/search?jql=attachments%20is%20not%20empty&fields=attachment&maxResults=50&startAt=$i" --header 'Accept: application/json' --user '<email address>:<Token>' | jq '.issues[] | { key: .key, attachment: .fields.attachment[] } | select(.attachment.size > 2000000) | "\(.key) => \(.attachment.filename) => \(.attachment.size)Bytes"'
done
You can replace '2000000' with another size to find issues with attachments greater than that.
Note: This document is a workaround on best effort basis and support will not be responsible for troubleshooting on HOMEBREW or JSON Query.
We have used them as mere means to depict that information can be fetched via APIs and be further filtered to get the end results.
Was this helpful?