Jira scriptrunner Get user role

I am try to list all projects that a user is a Project Administrator, got code below with error on line 26. Any advise?

import com.atlassian.jira.bc.projectroles.ProjectRoleService;
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;

StringBuilder output = new StringBuilder();
ProjectManager projectManager = ComponentAccessor.getProjectManager();
ProjectRoleService projectRoleService = (ProjectRoleService) ComponentAccessor.getComponentOfType(ProjectRoleService.class);
ProjectRoleManager projectRoleManager = (ProjectRoleManager) ComponentAccessor.getComponentOfType(ProjectRoleManager.class);

final Collection<ProjectRole> projectRoles = projectRoleManager.getProjectRoles();
for(Project project : projectManager.getProjectObjects())
for(ProjectRole projectRole: projectRoles)
//for (RoleActor actor : projectRoleActors.getRoleActors()) {
// if(projectRole.getDescriptor().equals("Developers")) {
final ProjectRoleActors projectRoleActors = projectRoleManager.getProjectRoleActors(projectRole, project);
// name of role here
//final ProjectRole devsRole = projectRoleManager.getProjectRole("Project Administrators")
for (RoleActor actor : projectRoleActors.getRoleActors()) {
if(projectRoleManager.getProjectRole().equals("Project Administrators")){
output.append(project.getKey()).append(" : ").append(projectRole.getName()).append(" : ").append(actor.getDescriptor()).append("\n");
// }
// }
return output.toString();

I am  

1 answer

1 accepted

This widget could not be displayed.
Jenna Davis Community Champion Aug 28, 2017

I'm not sure what you're wanting to do throughout all of your code, but this should be a simple example to get you started. I have not tested it directly, but I think it should work. If you have any trouble,  please let me know. :)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager

def projectManager = ComponentAccessor.projectManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

def allProjects = projectManager.getProjects()
def adminProjects = []

def projectRoles = projectRoleManager.getProjectRoles(user, it)
if(projectRoles.find(){it.getName() == "Project Administrators"}){

return (adminProjects)

 Also, if you want to go more in detail with what you're trying to accomplish I can try to code something up for you. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

534 views 3 19
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you