Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,293,800
Community Members
 
Community Events
165
Community Groups

Inactivate jira user automatically via scriptrunner

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.

 

1 comment

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.

Like Suji Shyam likes this

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(',')}";

}

}

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Jira Software

Upcoming changes to epic fields in company-managed projects

👋 Hi there Jira Community! A few months ago we shared with you plans around renaming epics in your company-managed projects. As part of these changes, we highlighted upcoming changes to epics on...

14,130 views 34 44
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you