How to use the Groovy Script Runner to remove user from jira users-group

Ada Lin March 26, 2015

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. 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2015

You can use com.atlassian.jira.user.util.UserUtil#removeUserFromGroup

 

Ada Lin March 29, 2015

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))

Ada Lin March 29, 2015

Successful execution. I revised the code. userUtil.removeUserFromGroup(userUtil.getGroup("jira-users") ,userUtil.getUser(username)) Thank you very much. Ada Lin

Like Рогов Денис likes this
Rumceisz April 1, 2015

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

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 2, 2015

iterate over the users and call remove... for each one.

ioann sys November 4, 2017

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/>"

Peddinti Hemanth Satyakumar April 25, 2019

Hi Jamie,

     Is it possible to remove the users from the group by using GroupService?

Regards,

Hemanth.

TAGS
AUG Leaders

Atlassian Community Events