You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
Recently, I faced to interesting and challenging task.
We are moving one huge Jira instance to unified Access Management, which will be driven by user request in dedicated project and approved / declined request will automatically add users to users groups, which are shared in Permission Scheme through more projects.
Well, this part will be covered in another article, but as a predisposition, I had to migrate all of the users from Projects Roles to User Groups.
Doing this manually would take hours, maybe days with possibility of making a lot of mistakes.
So I took inspiration @JamieA answer over there https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-list-all-members-of-a-certain-project-role/qaq-p/528122 and created a script for that.
As sharing is caring, I would like to share this with everyone, because I find this quite useful :-)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.bc.project.component.ProjectComponentManager
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
ProjectRoleManager projectRoleManager = ComponentAccessor.getOSGiComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager
def projectComponentManager = ComponentAccessor.getComponent(ProjectComponentManager)
def projectManager = ComponentAccessor.getComponent(ProjectManager)
def groupManager = ComponentAccessor.getGroupManager()
def usersKeyString
def usersObjList = []
ProjectRole devsRole = projectRoleManager.getProjectRole("Developers") //SOURCE: Change to appropriate Project Role
def group = groupManager.getGroup("group_developers") //TARGET: Change to appropriate Jira Group
def Projects = projectManager.getProjectObjByKey("FOO") //PROJECT: Change to Project you are working with
for (item in Projects)
{
ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(devsRole, item)
usersKeyString = ("${actors.getUsers()*.key}").toString()
}
usersKeyString = usersKeyString.replace("[","")
usersKeyString = usersKeyString.replace("]","")
usersKeyString = usersKeyString.replace(" ","")
def usersKeyList = usersKeyString.split(',').collect {it as String}
for (item in usersKeyList)
{
def userObject = ComponentAccessor.getUserUtil().getUserByKey(item)
if (userObject != null)
{
usersObjList.add(userObject)
}
}
for (item in usersObjList)
{
groupManager.addUserToGroup(item,group)
}
I also refactored original @JamieA answer, as It contain deprecated Component Manager and few not anymore available method. (Unfortunately original thread is locked, so I cannot post answer over there).
So here is the script compatible with Jira 8.x version which will generate list of specified Project role in all projects:
Key | Name | Lead | Member
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.bc.project.component.ProjectComponentManager
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
ProjectRoleManager projectRoleManager = ComponentAccessor.getOSGiComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager
def projectComponentManager = ComponentAccessor.getComponent(ProjectComponentManager)
def projectManager = ComponentAccessor.getComponent(ProjectManager)
def actorsList = []
def instanceList = []
ProjectRole devsRole = projectRoleManager.getProjectRole("Developers") //Specify the project role you would like to list across the Jira
def Projects = projectManager.getProjectObjects()
for (item in Projects)
{
ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(devsRole, item)
instanceList.add("$item.key, $item.name, $item.lead, ${actors.getUsers()*.name}\n")
}
return instanceList
Tomáš Vrabec
Atlassian Solution Architect & Consultant
Freelancer
Czechia
3 accepted answers
I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
2 comments