How to make cleanup rules avoid the "latest" tag?

I can’t see it mentioned anywhere… how can I create a cleanup rule which would avoid removing the “latest” tag?

I’m worried that for some images we might be updating really infrequently a “generic” rule (like, say, delete anything older than 365 days) might catch our latest tags as well, and those we’d rather keep (even if old).

Hi @mbender - I ran your question through Ask Sona, our Sonatype-trained AI Support. This is what it had to say (also, if you ever want to use it in the future, you can click the Ask Sona button in the bottom right corner to ask a question. It runs through a bunch of Sonatype resources to get you an answer!)

Currently, Nexus Repository Manager does not have a built-in feature to exclude certain tags, such as ‘latest’, from the cleanup policies.

However, there are a few workarounds that have been suggested:

  1. Using an external job to periodically download the image so it stays active and violates the cleanup timeframe condition. This would make the system think that the image is still in use and hence, it won’t be deleted.

  2. Potentially using a regex exclusion in the asset name matcher portion of a cleanup policy. This would involve creating a policy that excludes certain names or tags.

It’s worth noting that there is an ongoing discussion about implementing a feature that would allow for more advanced cleanup rules, such as retaining a minimum number of historical versions or excluding certain tags from cleanup. You can follow the progress of this feature request and even comment on it in the Sonatype Ideas Portal.

In the meantime, you might consider moving the ‘latest’ tags to another hosted repository which doesn’t have the cleanup policy associated, or moving old tags to another repository which has the cleanup policy. This would ensure that your ‘latest’ tags are not accidentally deleted during cleanup. Please note that these are just workarounds and may not be perfect solutions. It’s always a good idea to keep a backup of your important images and tags.

Re. the #2 suggestion - I’ve tried that but had no luck creating a working regex. I was using a negative look-ahead type definition, but it would exclude everything, not just the latest tag (even if my tests using tools such as https://regex101.com/ appeared to work correctly).

Could someone make a script for the task ( Admin - execute script) to do it