We have 10 projects and we want them to have a scriptrunner job every day to synchronize all users with their project roles so it would be same. I tried to write a script but it did not work for us. Could you please help?
Could you please try the next?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.user.ApplicationUser
def projectManager = ComponentAccessor.projectManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def projectKeys = ['PROJECT1', 'PROJECT2', 'PROJECT3', 'PROJECT4'] // Agrega los demás proyectos necesarios
def projects = projectKeys.collect { projectManager.getProjectByCurrentKey(it) }
// Función para asignar usuario al rol si no está en el proyecto destino
def assignUserToRoleInProject(ApplicationUser user, ProjectRole role, Project project) {
if (!projectRoleManager.isUserInProjectRole(user, role, project)) {
projectRoleManager.addActorToProjectRole(user, role, project)
}
}
projects.each { Project project ->
projectRoleManager.getProjectRoles().each { ProjectRole role ->
// Obtener usuarios actuales en el proyecto y rol actual
def currentMembers = projectRoleManager.getProjectRoleActors(role, project).getApplicationUsers()
currentMembers.each { ApplicationUser user ->
// Asignar usuario al mismo rol en otros proyectos
projects.findAll { it != project }.each { Project targetProject ->
assignUserToRoleInProject(user, role, targetProject)
}
}
}
}
return "Synchronización completa para los proyectos: ${projectKeys.join(', ')}"
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.