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

0 votes
Accepted answer
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 Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

413 views 0 3
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