Hi guys,
I would like to use groovy script runner to remove user from JIRA user-group (not assign to any group).
The expected result is like the following image
圖片1.png
I try to use userUtil of JIRA api like removeUser(), but it will delete the user and removes the user from all the groups.
Do you have any idea?
Thanks.
Community moderators have prevented the ability to post new answers.
You can use com.atlassian.jira.user.util.UserUtil#removeUserFromGroup
Hi, thank you for your answer. The first parameter is group (the group to add the user to). How should I fill it? null? import com.atlassian.jira.component.ComponentAccessor def userUtil = ComponentAccessor.getUserUtil() userUtil.removeUserFromGroup(null,userUtil.getUserByName(username))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Successful execution. I revised the code. userUtil.removeUserFromGroup(userUtil.getGroup("jira-users") ,userUtil.getUser(username)) Thank you very much. Ada Lin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, the code is perfect. Anyway we'd like to apply it for 100+ users. How can the code be modified to use it all at once for the 100+ users? We tried to use it like this: import com.atlassian.jira.component.ComponentAccessor def userUtil = ComponentAccessor.getUserUtil() userUtil.removeUserFromGroup(userUtil.getGroup("groupname") ,userUtil.getUsers('user1';'user2';'user3')) but it sent an exception. Wat is wrong in the code? getUsers? or the separation? ";" Please help! Thank, Rumi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
iterate over the users and call remove... for each one.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
UserUtil userUtil = ComponentAccessor.getUserUtil()
def result = ""
def allUsers = userUtil.getAllApplicationUsers()
// u need use iterator in each cycle
allUsers.each{ u ->
result += u.name + "<br/>"
if (userUtil.getGroupNamesForUser(u.name).contains("jira-users") )
{
System.out.println("The user " + u.name + " in jira-users group")
userUtil.removeUserFromGroup(userUtil.getGroup("jira-users"), u)
// userUtil.removeUserFromGroup(userUtil.getGroup("jira-developers"), u)
}
}
"All users = " + allUsers.size().toString() + "<br/>" + result + "<br/>"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
Is it possible to remove the users from the group by using GroupService?
Regards,
Hemanth.
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.