Inactivate jira user automatically via scriptrunner

Suji Shyam July 29, 2020

Need an exact script to inactive the jira users.

we have the users to be inactive in a list and the list of users is to be inactive.

 

2 answers

1 vote
Stephen Garber
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 31, 2020

Adaptavist has a script documented here that will deactivate idle users: https://library.adaptavist.com/entity/deactivate-idle-users

 

Just be sure to test this in a lower environment before deactivating users in production.

0 votes
Suji Shyam August 7, 2020

Also a tried a script to inactive the users.

One can run this script in the scriptrunner console and get the users inactivated. Successfully got the result.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.crowd.embedded.api.User
import com.atlassian.crowd.embedded.impl.ImmutableUser
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.crowd.embedded.api.UserWithAttributes


UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService.class);
UserSearchParams userSearchParams = new UserSearchParams(true, true, false);
//String pattern = "@dummy.com"
List<ApplicationUser> userList = userSearchService.findUsers("","@dummy.com", userSearchParams);
def namePrint = ""
userList.each{
//namePrint += it.displayName
namePrint += it.name + "<br>"
}
// return namePrint.split("<br>") // [appuser242, appuser245, jegi01, sankesw]
String[] nameofactive = namePrint.split("<br>")
int i
for (i=0; i<=nameofactive.size(); i++)
{
CrowdService crowdService = ComponentAccessor.crowdService
UserWithAttributes user = crowdService.getUserWithAttributes(nameofactive[i]);
UserService userService = ComponentAccessor.getComponent(UserService)
ApplicationUser updateUser = ApplicationUsers.from(ImmutableUser.newUser(user).active(false).toUser());
UserService.UpdateUserValidationResult updateUserValidationResult = userService.validateUpdateUser(updateUser)

if (updateUserValidationResult.isValid()) {

userService.updateUser(updateUserValidationResult)

} else {
log.error "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}";

}

}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events