How can we activate and deactivate a user in JIRA using groovy script that can be run from script console. I already have the user details which I want to activate first and then make them inactive again.
Hi @SWAPNIL SRIVASTAV ,
Please refer below documentation link.
https://library.adaptavist.com/entity/deactivate-users
import com.atlassian.jira.bc.user.UserServiceimport com.atlassian.jira.component.ComponentAccessordef userManager = ComponentAccessor.userManagerdef userService = ComponentAccessor.getComponent(UserService)def active =true[ 'anuser', 'otheruser', // add more as required].each { username -> def user = userManager.getUserByName(username) if (!user) { log.warn "Failed to find user with name ${username}" return } def updatedUser = userService.newUserBuilder(user).active(active).build() def updateUserValidationResult = userService.validateUpdateUser(updatedUser) if (updateUserValidationResult.valid) { log.warn "Deactivating user ${username}" userService.updateUser(updateUserValidationResult) } else { log.warn "Update of ${user.name} failed: ${updateUserValidationResult.errorCollection.errors.entrySet().join(',')}\n" }}
Set the active variable to true or false for activating and deactivating respectively.
Regards,
Anzar
@Anzaris there a cloud version of this script?
It looks like you're new here. Sign in or register to get started.