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.
×How can I use the Groovy Runner jira user id rename form the command line?
I need to run this for 500 users and I do not enjoy using the web interface for this.
/secure/admin/groovy/CannedScriptRunner.jspa?cannedScript=com.onresolve.jira.groovy.canned.admin.RenameUser#parameters
Jamie's snippet was a great help, but I found that it didn't work directly for me with Script Runner 2.0.7 on JIRA 4.4. (The ComponentManager wasn't able to get the needed components, presumably because SR is now a versions 2 plugin.)
Here is a complete, working example that I fixed up to work with JIRA 4.4.5 and the above version of Script Runner. Obviously, YMMV with other versions of either product.
If you want to merge users rather than rename them, change the "(renameUser.FIELD_MERGE): 'false'," piece to read 'true' instead. Note that you seemingly need to pass a String containing the text 'true' or 'false', rather than a real boolean.
You may also want to change the log.error() calls to a different log level--I only did this because I was lazy and I didn't bother to lower the logging threshold to debug for just one script run.
import com.atlassian.jira.util.ErrorCollection; import com.atlassian.jira.ComponentManager; import com.atlassian.plugin.PluginAccessor; import org.apache.log4j.Level import org.apache.log4j.Category; Category log = Category.getInstance(this.getClass()); ComponentManager componentManager = ComponentManager.getInstance(); PluginAccessor pluginAccessor = componentManager.getPluginAccessor(); Class scriptManagerClass = pluginAccessor.getClassLoader().findClass("com.onresolve.jira.groovy.ScriptManager"); Class cannedScriptRunnerClass = pluginAccessor.getClassLoader().findClass("com.onresolve.jira.groovy.CannedScriptRunner"); def scriptManager = ComponentManager.getOSGiComponentInstanceOfType(scriptManagerClass); def groovyClassLoader = scriptManager.getGcl(); Map allUsers = new HashMap(); allUsers.put("user1_from", "user1_to"); allUsers.put("user2_from", "user2_to"); // repeat for as many users as necessary for (Map.Entry entry : allUsers.entrySet()) { String fromUser = entry.getKey(); String toUser = entry.getValue(); log.error("** Mapping user " + fromUser + " to " + toUser); def renameUser = groovyClassLoader.loadClass("com.onresolve.jira.groovy.canned.admin.RenameUser", true, false).newInstance(); Map<String, Object> inputs = [ (renameUser.FIELD_FROM_USER_ID) : fromUser, (renameUser.FIELD_TO_USER_ID): toUser, (renameUser.FIELD_MERGE): 'false', ] as Map<String, Object> ErrorCollection errorCollection = renameUser.doValidate(inputs, true) if (errorCollection.hasAnyErrors()) { log.error errorCollection } else { def cannedScriptRunnerConstructor = cannedScriptRunnerClass.getConstructor(scriptManagerClass); def cannedScriptRunner = cannedScriptRunnerConstructor.newInstance(scriptManager); Map returnVars = cannedScriptRunner.runCannedScript(renameUser.class.getName(), inputs); } } log.error("** RenameUser All done!");
> Note that you seemingly need to pass a String containing the text 'true' or 'false', rather than a real boolean.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Scott,
when I run this script, I get the following error:
java.lang.ClassNotFoundException: com.onresolve.jira.groovy.ScriptManager at com.atlassian.plugin.classloader.PluginsClassLoader.findClass(PluginsClassLoader.java:122) at Script29.run(Script29.groovy:11)
I use JIRA 6.3.11. Is there any class changed in the meantime?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I haven't looked at this script in years, but it appears that the JIRA CLI can now rename users on JIRA 6.1+.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When I need to do this I created a script for it... see below. Otherwise you could use wget/curl.
in some loop of users... log.debug "Merge from $mergeFrom to $k" ScriptManager scriptManager = (ScriptManager) ComponentManager.getComponentInstanceOfType(ScriptManager.class); GroovyClassLoader gcl = scriptManager.getGcl(); CannedScript renameUser = (CannedScript) gcl.loadClass("com.onresolve.jira.groovy.canned.admin.RenameUser", true, false).newInstance(); Map<String, Object> inputs = [ (renameUser.FIELD_FROM_USER_ID) : mergeFrom, (renameUser.FIELD_TO_USER_ID): k, (renameUser.FIELD_MERGE): true, ] as Map<String, Object> renameUser.log.setLevel(Level.DEBUG) ErrorCollection errorCollection = renameUser.doValidate(inputs, true) if (errorCollection.hasAnyErrors()) { log.error errorCollection } else { runner.run(renameUser.class.getName(), inputs) } end loop
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I'm up to do the same thing, but I need to ensure that user ID rename/merge works correctly with a single user first.
What I'm planning to do is to take the source from the script and insert a new method to iterate through users in chuncks of 10-20, taking backups in the meantime (better be safe than sorry).
Then, save and execute this as a new custom script. I hope this helps you.
However, the rename doesn't work for me yet, it throws a bounch of warnings during preview, something about missing components.
So, the rest of my comment is a little out-of-topic:
The log says (just one of those entries):
Unable to find component with key 'class com.atlassian.jira.issue.search.CachingSearchRequestStore' - eventually found 'com.atlassian.jira.issue.search.CachingSearchRequestStore@358b7a35' the slow way.
When I click run, it goes on with renaming but it doesn't complete it (no issues are transferred but user is renamed, groups and roles are also updated). Then I have to restore everything from backup.
Did you make it with a single user?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"Unable to find component with key"
This is annoying but expected, I have an unanswered question on this on this forum.
Without seeing the logs I couldn't tell what is going wrong in your case.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Jamie for reply,
Where can I send you the full log? Should I create a new issue in GRV project @ studio.plugins.atlassian.com?
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
New issue created on https://studio.plugins.atlassian.com/browse/GRV-161
thx
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.