Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Groovy code to get users list of certain project role of Jira Project

Groovy code to get users list of certain project role of Jira Project

I have a requirement of displaying the approvers name specific to project role in Jira beside the approver stage

Like for example for development role users are added to project role developers same users list need to be displayed beside  Development approve field

2 answers

I needed to get Users per Role.

ComponentManager was deprecated, use ComponentAccessor instead:

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

def projectManager = ComponentAccessor.getProjectManager()
def projectRoleManager = ComponentAccessor.getComponent (ProjectRoleManager)

// name of role here
ProjectRole devsRole = projectRoleManager.getProjectRole("Developers")

def result = ""

projectManager.getProjectObjects().each {Project project ->
ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(devsRole, project)
result += "$project.key, $project.name, $project.lead, ${actors.getUsers()*.name}\n"
}

return result

Hi,

You can try this code (based on THIS answer)

import com.atlassian.jira.ComponentManager
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

ComponentManager componentManager ComponentManager.getInstance()
ProjectManager projectManager componentManager.getProjectManager()
ProjectRoleManager projectRoleManager ComponentManager.getComponentInstanceOfType(ProjectRoleManager.classas ProjectRoleManager

// name of role here
ProjectRole devsRole projectRoleManager.getProjectRole("Developers")

def result ""

projectManager.getProjectObjects().each {Project project ->
    ProjectRoleActors actors projectRoleManager.getProjectRoleActors(devsRoleproject)
    result += "$project.key, $project.name, $project.lead, ${actors.getUsers()*.name}\n"
}

return result

 

Regards,
Marcos

Hello @Marcos Sanchez , @Oleksandr Chalyi 

How to get users list with direct permissions of certain project role of Jira Project.

At the moment this script is listing all users including group members.

Is there any method to list only users with direct permission from certain roles.

 

Thanks in advance

Regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

⏰ Day in the life of a Jira Admin!

Hello Community! We thoroughly enjoyed this just-for-fun conversation in the Jira Admin Group about what it's like to be a Jira Admin. For #JiraJuly, our talented designers created these graphics t...

899 views 2 22
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you