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?
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:
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 <").append(newUser.getUsername()).append(">"); } catch (Exception e) { sb.append(": failed to rename: "+e.getClass().getName()+": "+e.getMessage()); } } sb.append("<br/>\n"); } return "Result:<br/>"+sb.toString();
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Drew G ,
are you migrating from Server to Cloud? Or is this a Cloud to Cloud movement?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
Do let me know if this helps solve your use case
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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*.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.