Hello everyone,
I'm looking to write a script that bulk adds a group called "New Group" with the project role "Read & Write" to specific projects using their keys ["ABC", "DEF", "GHI"].
The script I have below bulk adds the group w/ attached role to ALL projects in Jira, but I'm trying to modify the second to last block of code (highlighted below) to only add the group w/ attached role to specific projects by key within an array:
// Script to add group to project role in ALL Jira projects
import com.atlassian.jira.bc.projectroles.ProjectRoleService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleActor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.util.SimpleErrorCollection
def groupManager = ComponentAccessor.getGroupManager()
def projectManager = ComponentAccessor.getProjectManager()
def projectRoleService = ComponentAccessor.getComponent(ProjectRoleService)
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def errorCollection = new SimpleErrorCollection()
// Fetch project role object by name
def projectRole = projectRoleManager.getProjectRole("Read & Write")
// Fetch group (case insensitive) and add to list (addActorsToProjectRole requires a list)
def group = groupManager.getGroup("New Group").name
def list = new ArrayList<String>()
list.add(group)
// MODIFY THIS BLOCK TO PULL SPECIFIC PROJECTS FROM AN ARRAY! Fetch ALL Jira projects and loop add group to project role on each project
def projects = projectManager.getProjects()
for(item in projects) {
projectRoleService.addActorsToProjectRole(list,projectRole,item,ProjectRoleActor.GROUP_ROLE_ACTOR_TYPE,errorCollection)
}
// Print errors in log
log.warn(errorCollection)
Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.