0
votes

I have a question about usage of the Artifactory REST API. Some guidance would be useful.

I'm building a script that exercises Artifactory's REST API. The goal of this script is to find artifacts that are old, meet some other requirements, and then delete them. (Doesn't every Artifactory owner end up building one of those?)

There is a documented "Artifacts Not Downloaded Since", which returns a list of files. For "artifacts" I would rather have expected some concept that contains multiple files (like for Maven: a POM and a few JARs). The fact that it returns just single files has me now strip the file name, then delete the whole folder.

  1. Query returns: https://.../repository/api/storage/libs-snapshot-local/com/x/y/1.0.0-SNAPSHOT/y-1.0.0-SNAPSHOT.jar
  2. I strip: https://.../repository/api/storage/libs-snapshot-local/com/x/y/1.0.0-SNAPSHOT/
  3. I delete that stripped folder.

I am scared that the folder in question contains other files (a POM file or some other file in that folder) that was downloaded more recently, yet still gets deleted now.

Why is this stuff not reported by the REST API on the artifact level (GAV level)?

For Docker repositories a related question, does "Not Downloaded Since" at all consider child containers? Or is there an approach that I should use to just delete the tag, and Artifactory will auto-remove the associated, but unused, image/layer files?

1

1 Answers

8
votes

For Docker cleanup you need to use different REST API: Deletion and Cleanup for Docker.

The REST API artifacts not downloaded since returning only the artifacts that were not downloaded for the amount of time. It does not check the GAV level. There could be other artifacts within this folder that were downloaded recently. There is actually a sample script that you can find in this blog that provides an example for cleanup artifacts. You can add your logic to this script and usq AQL to get your purpose. Also, if you are running the Artifactory Pro addition then you can use Artifactory ability to be extended by using user plugin. There is also a sample user plugin that you can find on Github in JFrog public repository --> The user is JFrogDev. You can create a user plugin that will meet your requirements.