Hi, May I know how to add a user as admin or other roles in hundreds of projects at once? Please give specific operation steps. Thank you so much.
Hi @Jason Liu it depends on your configuration. For example if you use one permission scheme for all the projects, you can easily add single user to the specific permission and it is set on every project.
Can you describe your environment in more detail?
@Jason Liu
One way to do this is to use for example ScriptRunner and run a script that populates a certain role with a certain user or a certain group.
HTH,KGM
Hi @Jason Liu ,
using script runner (Script console), you can add user as project admin using the following code :
import com.atlassian.jira.bc.projectroles.ProjectRoleServiceimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.security.roles.ProjectRoleActorimport com.atlassian.jira.security.roles.ProjectRoleManagerimport com.atlassian.jira.util.SimpleErrorCollectiondef groupManager = ComponentAccessor.getGroupManager()def projectManager = ComponentAccessor.getProjectManager()def projectRoleService = ComponentAccessor.getComponent(ProjectRoleService)def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)def errorCollection = new SimpleErrorCollection()def projects = ["projectkey1", "projectkey2", "projectkey3"]for (pname in projects) { def actors = ['user_name_of_user_to_be_added'] def project = projectManager.getProjectObjByKey(pname) def projectRole = projectRoleManager.getProjectRole("Administrators") def projectService = ComponentAccessor.getComponentOfType(ProjectRoleService.class); projectRoleService.addActorsToProjectRole( actors, projectRole, project, ProjectRoleActor.USER_ROLE_ACTOR_TYPE, errorCollection)}
Hope this helps,
Fabio
Hi Fabio,
Thank you so much for your support. I have tried your runner. But nothing happened. Could you help me check where I'm wrong?
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()
def projects = ["LHWTST", "LHWTES", "LHWTST112"]
for (pname in projects)
{
def actors = ['gaoji1@lenovo.com']
def project = projectManager.getProjectObjByKey(pname)
def projectRole = projectRoleManager.getProjectRole("Administrators")
def projectService = ComponentAccessor.getComponentOfType(ProjectRoleService.class);
projectRoleService.addActorsToProjectRole(
actors,
projectRole,
project,
ProjectRoleActor.USER_ROLE_ACTOR_TYPE,
errorCollection)
}
are u sure that 'gaoji1@lenovo.com' is the USERNAME of your user?
I also tried "gaoji1" and nothing happened. User name can only be gaoji1 or gaoji1@lenovo.com. I have mapped the projects and all issue types also. Is there any other possible reason?
It looks like you're new here. Sign in or register to get started.