This question is in reference to Atlassian Documentation: Add, edit and remove users
How do you bulk delete or deactivate users?
There is no option in JIRA to do that, but there are plugins out there that can. User Deactivator for JIRA is one, or you could use the REST API and create your own plugin/script for it.
removeUser and updateUser with the deactivate parameter can be used. They are part of the JIRA Command Line Interface (CLI).
Hi Mikael
It would be great if you can provide the link for REST API.
You can find the documentation for all the REST APIs here, https://developer.atlassian.com/docs/?_ga=2.158361978.1985121612.1520266316-819614289.1519148677
In case it helps other searchers, I wrote the following script (as an amalgamation of other people's scripts) to handle this very quickly in the Scriptrunner console.
The goal was for this to be very reproducible, so hopefully it helps out. The example below is used to delete all users of a certain domain, but you could tweak it to use other search parameters.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.bc.user.search.UserSearchServiceimport com.atlassian.jira.bc.user.search.UserSearchParamsimport com.atlassian.jira.bc.user.UserServiceimport com.atlassian.jira.user.ApplicationUserdef userSearchService = ComponentAccessor.getComponent(UserSearchService.class);// The search will be case sensitive, so you may need to do multiple runs. (@abc.com, @ABC.com, etc)def domainToDelete = "@spam.email"// The deletion process does not scale well, so play with the number to delete and see what works best. 50-100 has worked well thus far.// You can test more safely by trying out 1 or 2 users as you confirm your rules.Integer deletionBatchSize = 50UserSearchParams userSearchParams = (new UserSearchParams.Builder()).allowEmptyQuery(true).includeActive(true).includeInactive(true).maxResults(deletionBatchSize).build();def userService = ComponentAccessor.getComponent(UserService)def asUser = ComponentAccessor.jiraAuthenticationContext.loggedInUseruserSearchService.findUsers(domainToDelete, userSearchParams).each{ String jiraUserName = it.getName(); // Confirm 100% that the user we are deleting is actually in the domain to delete by confirming that their // jira username ends with the domain // The search params can sometimes find matches based on domainToDelete if portions of the string exist in the userName without this protection if (jiraUserName.endsWith(domainToDelete)){ final UserService.DeleteUserValidationResult result = userService.validateDeleteUser(asUser, it) log.error "REMOVAL TEST - $it matched domain" if (result.isValid()) { // If you would like to test the script without actually deleting the users found, comment the line below out when you run it. userService.removeUser(asUser, result) log.error "REMOVAL SUCCESSFUL - $it" } else { log.error "REMOVAL FAILED - $it " + result.getErrorCollection().errorMessages } } else { log.error "REMOVAL SKIPPED - " + jiraUserName + " did not match domain: " + domainToDelete + " for removal"; }}
Patrick, do you think there would be any way to use this script to delete users based on a JQL statement? If so, can you please help! I getting very frustrated deleting/disabling users via the GUI. Thanks in advance!
Parker,
I never found a way to do it with JQL, just the Script Runner add-on.
After I posted the answer on this thread, I apparently wrote a Script Listener to block spam accounts (Service Desk portal sign-up) from getting created at all. Here you go in case it helps. Originally answered in this post.
import com.atlassian.jira.user.ApplicationUserimport com.atlassian.crowd.model.user.Userimport com.atlassian.crowd.event.user.UserCreatedEventimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.bc.user.UserService// Catch the UserCreatedEvent and get the Userdef newUserEvent = event as UserCreatedEvent; User newUser = newUserEvent.getUser();String email = newUser.getEmailAddress();// Define the domain you want to blockString spamDomain = "@spam.xyz";if (email.toUpperCase().endsWith(spamDomain.toUpperCase())){ log.error "SPAMBOT DETECTED! " + email; def userService = ComponentAccessor.getComponent(UserService) def userManager = ComponentAccessor.getUserManager(); // Set the user account we want to run delete permissions with ApplicationUser runAsUser = userManager.getUserByKey("yourJiraAdminAccount") // validate permissions final UserService.DeleteUserValidationResult result = userService.validateDeleteUser(runAsUser, email) if (result.isValid()) { log.error "SPAMBOT REMOVAL VALID - $email" userService.removeUser(runAsUser, result) log.error "SPAMBOT REMOVAL SUCCESSFUL - $email" } else { log.error "REMOVAL INVALID - $email" } }
import com.atlassian.jira.user.ApplicationUserimport com.atlassian.crowd.model.user.Userimport com.atlassian.crowd.event.user.UserCreatedEventimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.bc.user.UserService// Catch the UserCreatedEvent and get the Userdef newUserEvent = event as UserCreatedEvent; User newUser = newUserEvent.getUser();String email = newUser.getEmailAddress();// Define the domain you want to allowString allowedDomain = "@safeDomain.com";if (!email.toUpperCase().endsWith(allowedDomain.toUpperCase())) { log.error "EXTERNAL ATTEMPT DETECTED! " + email; def userService = ComponentAccessor.getComponent(UserService) def userManager = ComponentAccessor.getUserManager(); // Set the user account we want to run delete permissions with ApplicationUser runAsUser = userManager.getUserByKey("yourJiraAdminAccount") // validate permissions final UserService.DeleteUserValidationResult result = userService.validateDeleteUser(runAsUser, email) if (result.isValid()) { log.error "EXTERNAL ATTEMPT REMOVAL VALID - $email" userService.removeUser(runAsUser, result) log.error "EXTERNAL ATTEMPT REMOVAL SUCCESSFUL - $email" } else { log.error "EXTERNAL ATTEMPT REMOVAL INVALID - $email" } }
Thanks for the help Patrick! Much appreciated.
I wrote a blog post on how to bulk edit Jira user e-mail accounts, it can be easily changed to perform other operations like deactivation.It's based on ScriptRunner and Groovy.
Cheers!
It is surprising that the Administration page does not provide a datatable like interface to select multiple users/records and perform actions. Such basic feature is lacking!
I agree with @Anil this should be a simple native capability. I'm trying to understand why Atlassian does not allow this in the cloud version?
Hello @nudo
JIRA does not provide any provision to delete or deactivate users in Bulk. However, you can use the miniOrange Bulk User management plugin for JIRA. Along with bulk delete & deactivate operations, It allows you to automatically deactivate never logged-in users or users without any activity for a certain amount of time. Apart from this, you can even import or export users.
Feel free to reach out at atlassiansupport@xecurify.com in case of any further queries.
PS: I work for miniOrange, one of the top Atlassian SSO Vendors!
Hey @Patrick S 👋
by any chance, is there a script for Jira scriptrunner cloud, that you could provide for deleting in bulk?
Cheers, Alex
Hey @Alexander Ziegltrum
I am not aware of whether the script above would work with Script Runner cloud. Best bet would be to give it a try, and if it fails see which of the libraries the original script is referencing is the point of failure and use the newer library from there.
It looks like you're new here. Sign in or register to get started.