Remove old releases from a Maven2-repository in Nexus3
This Groovy-script will purge old versions (sorted by version-number) from a maven repository hosted on Nexus 3.x.
You can set the desired repository and a maximum amount of versions at the begining of this script.
Optional: define a retention (in days), so that old versions are only deleted if they are older than the retention.
After upgrading from Nexus 2.x to Nexus 3.x, the build-in function for keeping the latest X releases was sadly gone. Ofcourse there is an ongoing feature-request for that.
I tried the script by Matt Harrison from StackOverflow for this problem, but the migration-tool in Nexus had reset all last_updated-values to the date of the migration, sad again.
Now I tried to sort the releases by version via 'ORDER BY version DESC', but that resulted in a mess, where a version 3.9.0 is newer than 3.11.0 and so on, not a suitable scenario.
In the end, I forked Matt Harrison's script and the nice logoutput by Neil201
Added some helper-lists and the VersionComperator (a version sorter) by Rob Friesel
Finally, I linted the script with npm-groovy-lint to get a cleaner code, somehow
I later included the retention-feature kindly provided by agronlun and some cleanup/optimization by emetriqChris
- add the line nexus.scripts.allowCreation=true to $data-dir/etc/nexus.properties
- restart the Nexus-service, to apply the changes
- in the webinterface of Nexus, go to Administration > Tasks and create a new Execute script-task
- configure the task by filling out the required fields (Task name, Task frequency, etc.)
- copy 'n' paste all lines from nexus-cleanup.groovy into the Source-field
- disable further script creation, by adding a leading #-character to the line from step 1.
- restart the Nexus-service, once again
More information about setting up custom scripts, can be found in this article from the Sonatype Support Knowledge Base.
There is no warranty for the script or it's functionality, use it at your own risk.
No licensing at the moment, because this script is put together from various sites with different licensing schemes.
The icon/logo consists of the Nexus Logo © by Sonatype Inc. & a Broom Symbol © by HiClipart.
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at:
https://github.com/PhilSwiss/nexus-cleanup/issues
Development of nexus-cleanup
happens at GitHub: https://github.com/PhilSwiss/nexus-cleanup