Artifactory delete all artifacts older than 6 months
The jfrog cli takes a 'spec file' to search for artifacts. See here for information on jfrog spec files
The jfrog cli documentation is available here:
Create an aql search query to find just the artifacts you want:
If your aql search syntax were like:
/tmp/foo.query
items.find(
{
"repo":"foobar",
"modified" : { "$lt" : "2016-10-18T21:26:52.000Z" }
}
)
And you could find the artifacts like so:
curl -X POST -u admin:<api_key> https://artifactory.example.com/artifactory/api/search/aql -T foo.query
Then the spec file would be
/tmp/foo.spec
{
"files": [
{
"aql": {
"items.find": {
"repo": "foobar",
"$or": [
{
"$and": [
{
"modified": { "$lt": "2016-10-18T21:26:52.000Z"}
}
]
}
]
}
}
}
]
}
And you would use the golang library like so:
jfrog rt del --spec /tmp/foo.spec --dry-run
Instead of modified, you can also do a relative date
"modified": { "$before":"6mo" }
If you get error 405 Method not allowed, verify you have an api or password correct, and try using PUT instead of POST
Install jforg cli
configure jfrog cli to make API calls
jfrog rt c Artifactory --url=https://<>url/artifactory --apikey=<add api key> #can generate api key from user profile
Create a spec file called artifactory.spec You can change the find query as required. Below query will
display artifacts from
registry - docker-staging
path - *
download status = null # Not downloaded
created before 6 month
{ "files": [ { "aql": { "items.find": { "repo": {"$eq":"docker-staging"}, "path": {"$match":"*"}, "name": {"$match":"*"}, "stat.downloads":{"$eq":null}, "$or": [ { "$and": [ { "created": { "$before":"6mo" } } ] } ] } } } ]
You can search for the packages avalable to delete by
jfrog rt s --spec artifactory.spec
Run the delete command
jfrog rt del --spec artifactory.spec