How to bulk rename username

Stavros Michael
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.
February 4, 2015

I would like to use JIRA API to bulk rename usernames. I am currently using JIRA 6.3.14 and I am also having the Groovy Plugin installed. I am not able to find any API to help me achieve this. Can someone point me to the right direction. As we are maintaining a big user directory the use of Jira UI for manual update of the username is not an option

Thanks

2 answers

1 accepted

2 votes
Answer accepted
Stavros Michael
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.
February 8, 2015

I found a solution!

Using groovy

ImmutableUser.Builder builder = ImmutableUser.newUser(ApplicationUsers.toDirectoryUser(user));
builder.name(newName);
userManager.updateUser(new DelegatingApplicationUser(user.getKey(), builder.toUser()));
Melanie Wu February 13, 2017

Hi,

This may be a dumb question, but how do you use that groovy script?

Thanks,

Mel

Sumit Kumar
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.
February 15, 2017
import com.atlassian.jira.user.DelegatingApplicationUser
import com.atlassian.crowd.embedded.impl.ImmutableUser
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.component.ComponentAccessor;
UserManager userManager = ComponentAccessor.getUserManager();
ApplicationUser appUser = userManager.getUserByKey("<old_username>");
ImmutableUser.Builder builder = ImmutableUser.newUser(ApplicationUsers.toDirectoryUser(appUser));
builder.name("<new_username>");
userManager.updateUser(new DelegatingApplicationUser(appUser.getKey(), builder.toUser()));
Like Nirmani K likes this
1 vote
Luke Timms February 4, 2015

Wouldnt it be great if you could export all users, then import them again having made global changes.

JIRA ADMINS - This has been wanted/needed for many years.

Suggest an answer

Log in or Sign up to answer