Submitted by Tomek Kaczanowski on Wed, 11/14/2012 - 21:54

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.