Skip to main content
Example scripts
arrow icon
To homepage
Jira
Data centre icon
Data Center

Delete Group(s) in Jira

Created 1 year ago, Updated 1 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira (8.11 - 8.18)
compatibility bullet
ScriptRunner For Jira (6.30.2)
Language |
groovy
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.group.search.GroupPickerSearchService
import com.atlassian.crowd.embedded.core.util.StaticCrowdServiceFactory

// List of groups that will be removed
final def myGroupList = ['group1', 'group2', 'group3']

def crowdService = StaticCrowdServiceFactory.crowdService
def groupSearch = ComponentAccessor.getComponent(GroupPickerSearchService)
def groupManager = ComponentAccessor.groupManager

for (def group : myGroupList) {
    // Check whether the group exists
    if (!groupManager.allGroupNames.contains(group)) {
        log.warn "Group $group does not exist"
        continue
    }

    // Check if group is not empty
    if (groupManager.getUserNamesInGroup(group).size() != 0) {
        log.warn "Group $group is not empty"
        continue
    }

    // Remove the group and return the status
    def removeStatus = crowdService.removeGroup(groupSearch.getGroupByName(group))

    if (removeStatus) {
        log.warn "Removed group $group"
    }
}
Having an issue with this script?
Report it here