<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=949806081816595&amp;ev=PageView&amp;noscript=1">
Go Back

Jira Admin Tip #5: A Groovy Way to Find All Projects with a Specific Project Role

Amanda Kirk Amanda Kirk | August 17, 2021 | 3 MIN READ
Jira, Admin, Tip, Groovy, Projects, Role

Untitled-01

Here at Isos Technology, we've seen use cases for so many different scenarios! One that comes up now and then for both my clients (and myself, as an admin) is identifying all the projects where a specific project role is being used. Whether we're auditing permissions or looking to deprecate a role, we need to know who is using the role and if it can it be consolidated with another role.

Going through projects one by one to gather this information would take a heck of a long time, so in this blog post, I will show you how to utilize a simple Groovy script in order to quickly identify all projects using a project role. To run it, just pull up a Groovy console in Jira (note that a Groovy console comes with some typical apps like JMWE and may not be available out-of-the-box).

Let's jump right in: 

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.jira.security.roles.ProjectRole;
import com.atlassian.jira.security.roles.ProjectRoleActors;
import com.atlassian.jira.security.roles.ProjectRoleManager;
import com.atlassian.jira.security.roles.RoleActor;
 
def roleName = "Developers"
  
StringBuilder output = new StringBuilder();
ProjectManager projectManager = ComponentAccessor.getProjectManager();
ProjectRoleManager projectRoleManager = (ProjectRoleManager) ComponentAccessor.getComponentOfType(ProjectRoleManager.class);
  
//gets all project roles
def projectRoles = projectRoleManager.getProjectRoles()
  
//for each project
for(Project project : projectManager.getProjectObjects())
{   //and each project role
    for(ProjectRole projectRole: projectRoles)
    
        if(projectRole.getName() == roleName){
            //see if that project uses the project role
            def ProjectRoleActors projectRoleActors = projectRoleManager.getProjectRoleActors(projectRole, project)
            for (RoleActor actor : projectRoleActors.getRoleActors()) {
                    output.append(project.getKey()).append(" : ").append(projectRole.getName()).append(" : ").append(actor.getDescriptor()).append("\n")
                }
              
        }
    }
}
return output.toString();

 

As you can see from above, we use the ProjectManager and ProjectRoleManagers from the Jira API to iterate over all project roles in each project to see if the name matches the role we are looking for. In our example above, this is the project role "Developers." You can edit the script to find the specific project role you need. After it's found, it outputs the information along with which users OR groups are in that project role. Obviously, the output format can be changed to be more valuable for whatever you are trying to measure.

For now, though, here's a sample output generated from the script above:

 

image2021-4-21_17-22-8

 

And voilà! It's as simple as that! As you can see, the script outputs not only each project that is utilizing the project role, but which users or groups are utilizing that role within each project. I hope these script snippets can help speed your admin tasks or client needs.

And as always, happy automating!

New call-to-action

Recent Articles

jira vs ms project logos
Jira vs. MS Project: Why Jira outshines MS Project for Fortune 1000 companies
When it comes to project management tools for Fortune 1000 companies, the choice between Jira and MS Project can profoundly impact your organization's success.
Isos Technology Isos Technology 21 MIN READ
Read More
Jira vs Youtrack: Elevate your project management with Jira over Youtrack
When it comes to optimizing project management efficiency and success, Jira outshines YouTrack with its extensive features and user-friendly interface. From Agile adaptability to advanced reporting...
Isos Technology Isos Technology 16 MIN READ
Read More
Streamlining Collaborative Work: Unleashing the Power of Jira for Teamed Projects
Streamlining Collaborative Work: Unleashing the Power of Jira for Teamed Projects
Collaboration lies at the heart of any successful project. The ability of a team to work together seamlessly and efficiently can make or break the outcome of a project. One of the most powerful tools...
Holan Shetlar Holan Shetlar 3 MIN READ
Read More