Reputation: 11
I'm working with JFROG Cli and need to cleanup artifacts from folder under repository and keep only 5 latest artifacts (latest by created date).
I have already created some code which removes artifacts which were created 7 and more days. But I need to keep 5 latest artifacts. Anyone has any ideas?
{
"files": [
{
"aql": {
"items.find": {
"repo": "maven-repo",
"path": {"$match":"com/mqjbnd64/7.1"},
"name": {"$match":"*"},
"$or": [
{
"$and": [
{
"created": { "$before":"7d" }
}
]
}
]
}
}
}
]
}
Upvotes: 1
Views: 964
Reputation: 53
I got this to work by using the following file spec:
{
"$schema": "https://github.com/jfrog/jfrog-cli/blob/v2/schema/filespec-schema.json",
"files":
[
{
"aql":
{
"items.find":
{
"repo": "maven-repo",
"path": "com/mqjbnd64/7.1",
"name": { "$match": "*" },
"created": { "$before": "7d" }
}
},
"sortBy": [ "created" ],
"sortOrder": "desc",
"offSet": 5
}
]
}
Basically what it does is first query for all artifacts created before the last 7 days. It then sorts this list by creation date and removed the first 5 results via the offSet
.
Edit: this does not actually work entirely as I hoped since it only filters the packages that are older than 7d, so if there are X packages newer than 7d, it will keep X + 5 packages. But it is a start.
Upvotes: 0
Reputation: 15
You can create an initial query sorting by create date and limiting the number of records returned to 5. Than you can execute another query, to get all artifacts in this path, and deleted the ones not returned by the previous query.
Upvotes: 1