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.
×In the Project Versions list, when adding a new version it's inserted at the top of the list. It seems the only way to reorder the list is by drag/drop. This ability exists for sorting customer field options, but not in the Project Versions screen.
Is there a built in method (preferable) or an add-on (acceptable) that can sort the Project Versions list alphabetically? Currently running 6.3.12
I've thrown this together; a JIRA admin can run it using the Script Console under "Add-Ons":
import com.atlassian.jira.ComponentManager; import com.atlassian.jira.project.version.VersionManager; import com.atlassian.jira.project.version.Version; import com.atlassian.jira.project.ProjectManager; import com.atlassian.jira.project.Project; VersionManager versionManager = ComponentManager.getInstance().getVersionManager(); ProjectManager projectManager = ComponentManager.getInstance().getProjectManager(); Project project = projectManager.getProjectByCurrentKey("MYPROJECT"); List<Version> versions = versionManager.getVersions(project); if (versions != null && versions.size() > 0) { Collections.sort(versions, new Comparator<Version>(){ public int compare(Version obj1, Version obj2) { if (obj1 == null) { return -1; } if (obj2 == null) { return 1; } if (obj1.getName() == obj2.getName()) { return 0; } return obj2.getName().compareTo(obj1.getName()); } }); versionManager.moveToStartVersionSequence(versions[0]); for(int i=1;i<versions.size(); i++) { versionManager.moveVersionAfter(versionManager.getVersion(versions[i].getId()),versions[i-1].getId()); } } return versions;
I had to use "getVersion()" in the call to "moveVersionAfter()", because, otherwise, the signature of the Version object in the List didn't always match the underlying collection due to having been re-sequenced by a previous call, and so the method failed. Additionally, this is using the basic String.compareTo() comparison, which means "10" comes after "2"; with your version padding, that may not be an issue, but it's something I'll have to work on for my own in a bit.
If you uncomment "return versions" after the sort method, you can see what the sorted list will look like before running it with side effects enabled. And if you want them sorted in ASC order instead of DESC order, switch the ob2/ob1 in the compareTo call. And, of course, replace MYPROJECT with your project of interest.
Jeremy, this is fantastic, thank you for putting this together.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jeremy, I am currently trying to run this script in my own JIRA instance, but I am getting an error message.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 15: expecting ')', found ';' @ line 15, column 26. if (versions != null && versions.size() > 0) { ^ 1 error at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:26) at ScriptExecution1_groovyProxy.run(Unknown Source)
Any idea why this could be? Current JIRA version is 7.2.7
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't think there's a built-in way, though I think I could write an ad-hoc Script Runner script to do this fairly easily, and I actually have a use for that. Do you want to sort numerically or alphanumerically? I think the typical use case is by release date, which is why new versions are added to the top.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, I'd be looking for alpha numeric sort. Our versions are generally numeric (01.02.03), but some have alpha characters (01.02.Beta).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I ask because, in an alpha-numeric sort, 02 comes before 1; in a numeric sort, 1 comes before 02, or such is my interpretation. I suppose I could be making up the terminology; the unix "sort" utility also has "general numeric sort", which I'm not sure I understand, unless that's what I'm calling "alpha-numeric".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As long as everything is padded consistently, alpha-numeric sorting should work. However, I think "Beta" would come after any numeric values. Do you want non-numeric fields to come before numeric fields? It seems like you'd want "Beta", then "01", etc.
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.