Cleaning Old Artifactory Artifacts

Problem: growing number of our own released artifacts (JARs/WARs) in our Artifactory. Solution: regular cleaning. This post explains how.

The story is the following. On our road to continuous delivery we decided that every build ends up deployed to test server. The deployment goes via Artifactory, which means that artifacts (JARs and WARs) are first deployed from Jenkins there (with unique names denoting SVN revision and build number) and then taken from Artifactory and deployed to the test server.

This works pretty well, but it also means that every day we produce 1 GB or more of artifacts. This eats up the disk space and will eventually lead to OhMyGoshOutOfDiskSpaceError.

The solution

We decided to remove artifacts using Artifactory REST API (see http://wiki.jfrog.org/confluence/display/RTF/Artifactory%27s+REST+API).

The core pieces are:

1) querying for old artifacts with http://wiki.jfrog.org/confluence/display/RTF/Artifactory%27s+REST+API#Ar...
2) deletion of old artifacts with http://wiki.jfrog.org/confluence/display/RTF/Artifactory%27s+REST+API#Ar...

This is done via some Groovy scripts (which are run by Jenkins every night).

Additionally we want to keep artifacts which were deployed to production. In order to do this when deploying there we mark artifacts in Artifactory with metadata (see http://wiki.jfrog.org/confluence/display/RTF/Artifactory%27s+REST+API#Ar...) and then when attempting to delete we make sure first that this metadata is not present (see http://wiki.jfrog.org/confluence/display/RTF/Artifactory%27s+REST+API#Ar...).

BTW. Paid version of Artifactory allows to set properties for artifacts, which is probably better than metadata in this particular case, but since we used free version we have no choice.

Real cleaning

When you invoke DeleteItem method the item (artifact) won't be really removed. It is only marked as "deleted" (or whatever internal value Artifactory is using). The real deletion happens when Artifactory runs its Garbage Collection task. Go to Admin / Advanced / Maintenance and make sure it is configured. In our case Garbage Collections runs ~20 minutes after Jenkins job.

Backups

One more thing. If you are short of diskspace make sure to configure backups (do you need them?). See http://wiki.jfrog.org/confluence/display/RTF/Managing+Backups for details.

In our case the backups included all repositories which was not really needed. We saved ~20 GB by changing the backups settings.

Great post

Thanks, Tomek!

Just one subtle remark - metadata and properties are the same :)
Perfect, otherwise.

Need Help

I am new to Artifactory and back end of it. We have the same issue as this post but am unable to figure out how to run the searches and clear old artifacts ... Kindly help...

these are some of the details that may help...
I am running Artifactory version 2.3.3.1...
I dont know how to use REST API...
Thanks for your help

just google it up! :)

Hi,

regarding the REST API use all you need to do is some googling. :) You will find many responses, like this one on stackoverflow: http://stackoverflow.com/questions/3861527/what-is-rest-call-and-how-to-...

If you have some artifactory-specific questions it would be the best to ask them on artifactory forum.

--
Cheers,
Tomek Kaczanowski

 
 
 
This used to be my blog. I moved to http://tomek.kaczanowscy.pl long time ago.

 
 
 

Please comment using