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 ,
using script runner (Script console), you can add user as project admin using the following code :
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 = ["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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fabio,
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.