Dany
Dany

Reputation: 31

Artifactory old artifacts clean up (CLI + AQL)

I'm struggling to find a solution to clean up all RPM repositories from Artifactory using AQL and CLI. I would like for example to delete everything which was not downloaded in the last 12 months (also if the creation date is older than 1 year and it was never downloaded). The hardest part in my opinion is that I also need to keep the last x number of RPM files in each repository (for example the last 3 rpm files which were last downloaded). Any idea how to perform this task or if it is possible at all, especially the part with keeping the last downloads. Any suggestion is appreciated.

Thank you, Dany

Upvotes: 2

Views: 3365

Answers (1)

Jobin James
Jobin James

Reputation: 1030

Clean up old artifacts using jfrog CLI and AQL

JFrog CLI is a compact and smart client that provides a simple interface to automate access to Artifactory. As a wrapper to the REST API.

Installing JFrog CLI

On MAC

brew install jfrog-cli-go

With Curl

curl -fL https://getcli.jfrog.io | sh

JFrog CLI syntax

jfrog target command-name global-options command-options arguments

Target - product on which you wish to execute the command:

rt: JFrog Artifactory
bt: JFrog Bintray
mc: JFrog Mission Control
xr: JFrog Xray

Configure JFrog cli

jfrog rt c Artifactory --url=https://artifactory.eqs.intra/artifactory --apikey=<add api key> #can generate api key from user profile

Generate API Key

Login to artifactory -> Click on username and edit profile -> under Authentication Settings

JFrog CLI configuration Official Documentation

Search for Artifacts

display artifacts from - registry - docker - path - * - download status = null # Not downloaded - created before 1 month

{
  "files": [
    {
      "aql": {
        "items.find": {
          "repo": {"$eq":"docker"},
          "path": {"$match":"*"},
          "name": {"$match":"*"},
          "stat.downloads":{"$eq":null},
          "$or": [
            {
              "$and": [
                {
                  "created": { "$before":"1mo" }
                }
              ]
            }
          ]
        }
      }
    }
  ]
}

AQL Official Documentation.

Run a search and verify the packages you are about to delete

jfrog rt s --spec artifactory.spec 

Delete artifacts as per the spec file

jfrog rt del --spec artifactory.spec

Insight Page

Upvotes: 3

Related Questions