Find list of issues where attachments are added and their size is greater than 'xx'MB
Platform Notice: Cloud - This article 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 applied to MAC
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 which basically simplifies the process to install other packages on your MAC.
More details on HOMEBREW are here: https://brew.sh/
If you feel HOMEBREW is already installed you cuould check this by checking the version for the HOMEBREW on your systsem:
brew -v
Once it's confirmed that HOMEBREW is installed on your system, you just need to install the JQ package via the terminal:
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.
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
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.