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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,467,803
Community Members
 
Community Events
177
Community Groups

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

Atlassian Community Events