Here at Isos, we often come across problems that could potentially take substantial effort, and ask ourselves how we can provide a solution for clients that takes less time, less effort, and less budget. One problem I keep coming across recently, is the need to find all groups containing a specific number of users, in an efficient and easily repeatable way. Imagine you're being asked by auditors or a manager to find candidates for a group cleanup or consolidation. Looking at groups with less than a certain threshold of users would be a great way to identify these candidates!
In this blog post, I'll walkthrough how to quickly find all groups that have a specific threshold of members, by using a simple, groovy script that can be re-used time and time again! To run this script, just pull up a groovy console in Jira It's important to note that a groovy console comes with some typical add-ons like JMWE, and may not be available out-of-the-box.
In our example below, we will find all groups with 3 or fewer members. You can change the threshold variable to adjust this amount.
Use Case: Get a List of Groups with 3 or fewer Members
As you can see from the above, we use the GroupPickerSearchService from the Jira API to iterate over all groups in Jira. For each group, we get its user list to check how many members it contains, and if its member size is within our threshold, we take note of the results. You can also format the output any way you'd like, so there is no need for exporting and formatting in an external tool.
The only line that needs editing is line 8, where you define the threshold for your group. If you want to find all groups with 20 or fewer members, you would change that threshold variable to 20.
Here is some sample output to show you what the above script provides:
|asu-users has 0 users.
automated-tests has 1 users.
automation has 3 users.
bamboo-user has 2 users.
isos-conf-admin has 3 users.
isos-consulting-contractor has 2 users.
isos-pmo has 0 users.
isos-recruiting-contractor has 2 users.
isos-team-agile has 1 users.
isos-training has 2 users.
isos-ux-contractor has 3 users.
ms-jira-activity has 2 users.
nested-test has 2 users.
testme2 has 2 users.
timecard-approval-managers has 2 users.
And Voila! It is as simple as that! I hope these script snippets can help speed your admin tasks or client needs. And as always, happy automating!
Sign up to receive more great content
Learn more about Atlassian and how Isos can help by signing up to receive our latest blogs, eBooks, whitepapers and more.