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  

2 answers

1 accepted

0 votes
Answer accepted

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. 

It is a great snippet and it works. Thanks for your work!

Happy to help! 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


249 views 0 6
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