Blog - Isos Technology

A How-to on Pulling Jira Active User Lists with Groovy

Written by Amanda Kirk | Mar 23, 2021

Here at Isos Technology, implementing custom Groovy scripts for Jira is commonplace. Whether it's for cleanup, complex post functions in workflows, or other needed administration tasks, most Jira Admins become very familiar with utilizing Groovy because—as it turns out—it allows us to provide some seriously elegant and optimal solutions for even the most complicated of client needs. For whatever reason, you may find yourself, as I did, needing to pull a list of all active users for your Jira instance. You might need to analyze this set of data further or retrieve it for auditing purposes, for example. Whatever reason you have for needing a full list of active users in Jira, I will share a snippet of code with you to show you how easy it is to do just that. You ready? Let's jump into it!

Problem Statement - I Need a List of All Active Users in my Jira instance

First off, let's check how many active users are in our Jira instance from the User Management panel. This will help us to validate our results, since the resulting number of users from our script should match the number we see in Jira.

 

 

As you can see above, in User Management with Users selected, you will want to filter Application access to "All Users," filter Status to "Active" and then press the Filter button. You will then see the resulting number of users, which is 386 in the example above. So if we ran the script in the instance above, we could expect to see 386 users as a result of our Groovy script. Now let's take a look at the script!

 

Solution: Utilize a Groovy Script that Automates Pulling the List of All Active Users in Your Jira Instance

Note that you will need some added functionality in Jira in order to run a Groovy script in Jira. Most commonly this is provided by apps such as the SIL Groovy Connector.

 

 

As you can see above, we use the UserSearchService to find users based on the parameters defined in the UserSearchParams object. For more parameter options which you can pass to constrict or expand your search, see the Jira API reference. This basic search we are using is pretty open ended (not limited to just a specific query, such as only users that match a certain name pattern) and only includes active users. You'll notice if you run the above script that it will only return up to 1000 users. This is the default maximum results size. So if you have more than 1000 active users (as would have been identified when we checked the user count in Users Management) you'll want to add an additional parameter to the UserSearchParams object as shown in the below script. In the example below, I set the maximum results parameter to 8000 since I found 7500 users in my instance.

 

 

When we run the script we get a list of comma-separated usernames, which you can easily port over to a spreadsheet for further analysis. You can also gather more information on each user by iterating over this returned list and using the functions for Application Users listed here. The additional functions would allow you to gather the user's email addresses or full names, for example.

For more information on the classes and methods used in the script above, I suggest making the Jira API documentation a common reference. There are a ton of small tasks you can do with Groovy that would be HUGE tasks if done manually. And of course, you can use these scripts time and time again and also share them with your organization to stop re-inventing the wheel.

Hopefully the above snippet helps you in your quest to retrieve a list of all active users in your Jira instance. As always...Happy Automating!