How to Generate a List of All Labels in a Jira Instance
We have an updated version of this article available on the Polymetis Apps Blog.
Jira labels are a great way to quickly categorize issues. Everyone can add labels and they can do so anytime. Labels can also be easily searched and filtered making them a great fit for dashboard widgets and reports.
But how to view all the labels used in Jira? And how to find how many times a label is used in Jira? No, you do not need to compile it by hand! You can do it with one easy Jira Expression, of course! This article will show you how to use a combination of JQL and Jira Expressions to find all labels used in Jira and how often they have been used.
You do not need any extra apps to follow along – everything can be done via the Jira Expression REST API. However, the easiest way to work with Jira Expressions is to use our free app, Expression Tester. You can install the Expression Tester from the Atlassian Marketplace.
Selecting all issues with a label
First, we need to find all the issues that have one or more labels assigned to them. We can do that with a super-short JQL query: labels is not EMPTY
This returns a list of issues that we can work with in a Jira Expression. Of course, there is a lot of info in that list and we just want the labels. So let’s use map()
to only keep the label information and then flatten()
to turn a list of lists into a single list:
issues.map(l => l.labels).flatten()
Pretty good, but not quite what we want. That list contains a lot of duplicates and it would be cool if we had some idea how may times a label has been used. Again, Jira Expressions to the rescue! As we have explained here, thereduce()
function can help us by counting how many times it sees a label. Our final Jira Expression looks like this:
issues
.map(l => l.labels)
.flatten()
.reduce((result, label) =>
result.set( label, (result[label] || 0) + 1), new Map())
Putting that expression to work, we finally get a list of all labels in our Jira instance along with how many times they have been used:
And there you go: A list of all labels in your Jira instance, available with the click of a button. And easily downloadable as a JSON object. Depending on how intensively your team uses labels, you will probably see a lot more labels and a lot higher numbers.
Do you have a lot of labels? Want an easy UI to manage labels? Then Project Labels might be the right app for you. Check it out on the Atlassian Marketplace.
Conclusion
This has been a really quick and easy way to get a rough overview of the labels in your Jira instance, but of course, there’s always a catch. If you are an expert with Jira and JQL you can probably already guess: There is an in-built limit to how many issues are returned in a single query. So, for large instances, our quick and easy way will not cut it. If you happen to hit that limit, there are two things you can do:
- Limit the number of issues returned by JQL. Either by selecting only issues from a specific project or from a certain date range.
- Get a label manager for Jira Cloud such as our own Project Labels. This handy tool takes care of everything behind the scenes, displays your labels and lets you rename and delete them at will.
Hopefully, this short article was helpful for you and showed how versatile Jira Expressions are. Do you have any cool use-case for Jira Expressions? Let us know!