Skip to content

Remove old releases from a Maven2-repository on Nexus3

Notifications You must be signed in to change notification settings

PhilSwiss/nexus-cleanup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 

Repository files navigation

Nexus Cleanup Logo

Nexus-Cleanup

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.

Information

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

Installation

  1. add the line nexus.scripts.allowCreation=true to $data-dir/etc/nexus.properties
  2. restart the Nexus-service, to apply the changes
  3. in the webinterface of Nexus, go to Administration > Tasks and create a new Execute script-task
  4. configure the task by filling out the required fields (Task name, Task frequency, etc.)
  5. copy 'n' paste all lines from nexus-cleanup.groovy into the Source-field
  6. disable further script creation, by adding a leading #-character to the line from step 1.
  7. 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.

Disclaimer

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.

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at:

https://github.com/PhilSwiss/nexus-cleanup/issues

Contributing

Development of nexus-cleanup happens at GitHub: https://github.com/PhilSwiss/nexus-cleanup

About

Remove old releases from a Maven2-repository on Nexus3

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages