Due to some syncing error, we have over 2000 groups created in JIRA (all of those groups are empty). I am trying to find a scriptrunner code to bulk delete all of them. Any help would be appreciated.
Thanks
Something along these lines might work (untested)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.crowd.embedded.core.util.StaticCrowdServiceFactory
def crowdService = StaticCrowdServiceFactory.crowdService
def groupManager = ComponentAccessor.groupManager
groupManager.getAllGroups().findAll {
groupManager.getDirectUsersInGroup(it).size() == 0
}.each{
crowdService.removeGroup(it)
}
Thank you @Peter-Dave Sheehan. The script worked perfectly.
Is there a way to specify a particular set of groups say group1, group2, group3 and delete those?
Thanks,
bney
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Of course ...
Btw, if you haven't been looking there already ... you will want to start:
And while I was there, I noticed that "getAllGroups" is deprecated and may not work in the future.
The following will work:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.group.search.GroupPickerSearchService
import com.atlassian.crowd.embedded.core.util.StaticCrowdServiceFactory
def crowdService = StaticCrowdServiceFactory.crowdService
def groupSearch = ComponentAccessor.getComponent(GroupPickerSearchService.class);
def groupManager = ComponentAccessor.groupManager
def myGroupList = ['group1','group2','group3']
groupSearch .findGroups("").findAll {
groupManager.getDirectUsersInGroup(it).size() == 0 && it.name in myGroupList
}.each{
crowdService.removeGroup(it)
}
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.
@Peter-Dave Sheehan - quick question... if getallgroups is deprecated, what else would work? I have a usecase. I need to determine which are the groups which are associated with at least one configuration object within jira or confluence. All these groups are synced from AD in our case. So - my plan is to disable the sync, delete all groups - I would assume the delete would not work for groups which are tied with at least one object and I would hope it would capture the error and move forward ti the next group. We can decide that all groups that remain undeleted are the ones that are associated with at least an object and hence are required. The plan is to then add an attribute to those groups and change the filter and sync only those groups enabling the sync again. Let me know if this would work and what sort of a code I'm looking at for this? Any means to capture and refer the output/log of the execution?
Thanks and Regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure. I haven't messed with that sort of scenario.
In terms of non-deprecated alternatives for getting all groups in your instance there is now a "getAllGroupNames" method in the GroupManager class.
Or you can use the GroupPickerSearchService
import com.atlassian.jira.bc.group.search.GroupPickerSearchService
import com.atlassian.jira.component.ComponentAccessor
def allGroups = ComponentAccessor.getComponent(GroupPickerSearchService).findGroups('')
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.