I'm trying to find a way to delete users from JIRA software from the user directory: JIRA Internal Directory as they are already existing in the LDAP directories. There are about 1000 users to remove.
I am wondering if you can provide some guidance on using script console to delete the users.
The code I have is the following but does not capture the user directory piece.
import com.atlassian.jira.component.ComponentAccessor
def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager
def usersToRemove = ["exampleUser1","exampleUser2","exampleUser3","exampleUser4","exampleUser5"] //User Names
usersToRemove.each{
def currentUser = userManager.getUserByName(it)
}
The rest api: http://<JIRA URL>/jira/rest/api/2/user/
However I am getting a page cannot display error when launched.
Not familiar with scripting/coding.
Hi Mary,
From your Script Console you can try a script like
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
def userService = ComponentAccessor.getComponent(UserService)
def asUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
//usernames to remove
def userNames = ["Paolo", "Niki", "Christina", "Omar", "Peter", "Borge", "Anna", "Lena"]
userNames?.each { it ->
final UserService.DeleteUserValidationResult result = userService.validateDeleteUser(asUser, it)
if (result.isValid()) {
userService.removeUser(asUser, result)
log.info "User with username $it removed"
}
else {
log.error "Failed to remove user with username $it. " + result.getErrorCollection().errorMessages
}
}
Let me know how this went.
Regards, Thanos
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.