Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can we activate and deactivate a user in JIRA using groovy

SWAPNIL SRIVASTAV
Contributor
May 10, 2022

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.

3 answers

0 votes
afelts July 5, 2022

@Anzaris there a cloud version of this script?

0 votes
Anzar
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.
May 10, 2022
import com.atlassian.jira.bc.user.UserService

import com.atlassian.jira.component.ComponentAccessor




def userManager = ComponentAccessor.userManager

def 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

0 votes
Sreenivasaraju P
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.
May 10, 2022

Hi @SWAPNIL SRIVASTAV ,

Please refer below documentation link.

https://library.adaptavist.com/entity/deactivate-users

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Upcoming Jira Events