Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Possible to Bulk Change User Email Addresses?

Drew G
Contributor
August 2, 2023

Hello All - 

I am in a tough Jira situation with my organization. With the Configuration Management plugin, we are migrating (many) projects from one Jira instance to another. To make this process more complicated, ALL of the user accounts need to be updated. All of the users' email addresses will be different from what they currently are.

My organization does have Adaptavist Scriptrunner. Was hoping I'd be able to find a solution with this plugin, but it's not looking good.

Does anyone know if there is some kind of process that I could look into, which would involve me listing all OLD user account emails, mapping them to the new emails, and then being able to achieve this bulk change?

It's very clear that all things user management related are very limited in Jira. Has anyone had any kinds of similar experiences with this kind of task?

3 answers

0 votes
Ed Letifov _TechTime - New Zealand_
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.
August 3, 2023

Hello, @Drew G 

Below is the script that changes the usernames to be their emails.

Obviously it can be rewritten to leave usernames as is, or change them as per some predefined rule, or even from a 1:1 mapping, and/or only change the emails.

Notes:

  • We have commented out the line that actually updates the user record ("um.updateUser(newUser);") so that you can test the script first.
  • We have also added an exclusion of the "local-admin" user (you can change this to be your local admin user account/s).
  • See the comments in the script for more info and instructions including how to run on only users from specific domain.
  • Please run in a test environment first!

Here is the script:

import com.atlassian.jira.bc.user.UserService;
import com.atlassian.jira.bc.JiraServiceContext;
import com.atlassian.jira.bc.JiraServiceContextImpl;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.bc.user.search.UserSearchParams;
import com.atlassian.jira.bc.user.search.UserSearchService;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;
UserManager um = ComponentAccessor.getUserManager();
UserService userService = ComponentAccessor.getComponent(UserService.class);
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
JiraServiceContext jsc = new JiraServiceContextImpl(user);
UserSearchParams usp = UserSearchParams.builder()
                        .allowEmptyQuery(true)
                        .includeActive(true)
                        .includeInactive(false)
                        .ignorePermissionCheck(true)
                        .canMatchEmail(true)
                        .build();
UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService.class);

// you can specify a username-based search in the 1st argument or email-based search in the 2nd, // see: https://docs.atlassian.com/software/jira/docs/api/7.1.9/com/atlassian/jira/bc/user/search/UserSearchService.html#findUsers-java.lang.String-java.lang.String-com.atlassian.jira.bc.user.search.UserSearchParams-// e.g only for users with emails from domain.com:// List<ApplicationUser> list = userSearchService.findUsers("", "domain.com", usp); // with empty values - searches all usersList<ApplicationUser> list = userSearchService.findUsers("", "techtime.co.nz", usp);
StringBuilder sb = new StringBuilder("");

for (ApplicationUser aUser : list) {
    if ("local-admin".equals(aUser.getUsername())) continue; // we skip admin, please change to your admin's username    sb.append("user ").append(aUser.getUsername());
    if (!um.canRenameUser(aUser)) {
        sb.append(": cannot rename user")
    } else {
        try {
         ApplicationUser newUser = userService.newUserBuilder(aUser).name(aUser.getEmailAddress()).build();
        // uncomment this when you are ready to rename your users, otherwise will do a dry run, no changes, only logging        //      um.updateUser(newUser);            sb.append(": renamed to &lt;").append(newUser.getUsername()).append("&gt;");
        } catch (Exception e) {
            sb.append(": failed to rename: "+e.getClass().getName()+": "+e.getMessage());
        }
    }
    sb.append("<br/>\n");
}
return "Result:<br/>"+sb.toString();
Drew G
Contributor
August 3, 2023

Hi Ed -

Really appreciate the response. Unfortunately this script doesn't seem like it will get me to where I need to be.

In my Jira instance I have hundreds of old usernames with their corresponding email addresses.

I also have all of the updated username and email addresses in the Jira instance, which come from the Active Directory.

What I want to do is to swap all of the old username and email accounts with the Active directory username and email accounts, so that all of the existing Issues correspond to the user accounts coming from Active Directory.

Drew G
Contributor
August 3, 2023

Ed -

Reading more close into your response. Maybe the script you provided will solve my problem. It seems like it gives me the freedom to replace an existing user's username and email address. 

I will give this a shot tomorrow and report back!

 

One detail for clarification - When ready, I post this script into the Scriptrunner terminal window, correct?

Ed Letifov _TechTime - New Zealand_
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.
September 26, 2023

@Drew G 

On the 5th of August I've responded to the query you've raised via our support portal. Can you please confirm you've received my response – the email should have SUPPORT-17218 in the subject.

0 votes
Jehan Bhathena
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 2, 2023

Hi @Drew G ,

are you migrating from Server to Cloud? Or is this a Cloud to Cloud movement?

Drew G
Contributor
August 3, 2023

Hi Jehan - 

This is a Server to Server movement.... Does that change anything to your knowledge?

Jehan Bhathena
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 3, 2023

Hey @Drew G 

Thanks for the update.

While we were migrating from Server to cloud we faced a similar scenario.

We performed the below steps:

  1. Back up the old server's DB
  2. Log into the jiraDb and look into the User Table.
  3. Replace all the old domain with the new one and then migrate
  4. Once migrated you can chose to restore the old db back to the old Server or decommission the old server altogether

Do let me know if this helps solve your use case

0 votes
Artur Moura
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 2, 2023

Hi @Drew G

If the users are users from Jira Internal Directory, you may try to use a script to use REST API to update the users.

Here on this user-updateUser page, you may find more details about it.

Please let me know your thoughts.

Drew G
Contributor
August 3, 2023

So, the users we have on the instance (which we need to add as Assignees, Reports, etc.) all come from Active Directory. Any insight as to where that leaves me in this situation?

Artur Moura
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 3, 2023

In this case, the e-mail address comes from Active Directory too, so you would need to update it on AD.

In Jira User Directories you may find the mail attribute configuration under *User Schema Settings*.

image.png

If you are using an email address on your Active Directory that uses a different attribute for it, you may change it accordingly and this should reflect in Jira.

Drew G
Contributor
August 3, 2023

Thank you for the response! Looking around for the "User Schema Settings" page, but not finding it at the moment. Seeing the "User Directories" link on the User Management page, but options on that page don't offer much.

Just to clarify what I am trying to achieve:

- I imported a project via the Configuration Manager plugin, which imported all of the Issues, along with ALL of the current users as Reporters, Assignees, etc.

- All of the users mapped to these issues are now accounts created on my Jira instance

- These imported users all have outdated email addresses

- I need to swap all of the outdated emails with entirely different email addresses

Suggest an answer

Log in or Sign up to answer