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.ComponentAccessorimport com.atlassian.crowd.embedded.core.util.StaticCrowdServiceFactorydef crowdService = StaticCrowdServiceFactory.crowdServicedef groupManager = ComponentAccessor.groupManagergroupManager.getAllGroups().findAll { groupManager.getDirectUsersInGroup(it).size() == 0}.each{ crowdService.removeGroup(it)}
Thank you @PD 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
Of course ...
Btw, if you haven't been looking there already ... you will want to start:
https://docs.atlassian.com/software/jira/docs/api/7.13.2/com/atlassian/jira/component/ComponentAccessor.html
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.ComponentAccessorimport com.atlassian.jira.bc.group.search.GroupPickerSearchServiceimport com.atlassian.crowd.embedded.core.util.StaticCrowdServiceFactorydef crowdService = StaticCrowdServiceFactory.crowdServicedef groupSearch = ComponentAccessor.getComponent(GroupPickerSearchService.class);def groupManager = ComponentAccessor.groupManagerdef myGroupList = ['group1','group2','group3']groupSearch .findGroups("").findAll { groupManager.getDirectUsersInGroup(it).size() == 0 && it.name in myGroupList}.each{ crowdService.removeGroup(it)}
Worked like a charm.
Thank you @PD Sheehan
It looks like you're new here. Sign in or register to get started.