我有一个伪影问题。 我需要实施保留策略,每个文件夹仅保留 10 个工件。 我需要帮助。
这是我最初的curl命令,用于获取计数> 10的所有文件夹,
execute_aql() {
# Execute AQL query to find folders with more than 10 artifacts
curl_response=$(curl -s -u "admin:$API_KEY" -X POST "$ARTIFACTORY_URL/artifactory/api/search/aql" -H "Content-Type: text/plain" -d 'items.find({"type": "folder", "repo": "'"$REPO_NAME"'"}).include("name","children.items.name","children.items.@count").filter(function(item){ return item.children.items.@count > 10 })')
# Print the response
echo "$curl_response"
}
但它没有按预期工作,事实上它失败了:
+ ./retPolicy.sh
Failed to parse query: items.find({"type": "folder", "repo": "HLRP_GENERIC_DEV"}).include("name","children.items.name","children.items.@count").filter(function(item){ return item.children.items.@count > 10 }), it looks like there is syntax error near the following sub-query: children.items.name","children.items.@count").filter(function(item){ return item.children.items.@count > 10 })
我不知道为什么!
我想在其之上添加一个排序算法,按时间排序,并删除最旧的工件,但我没有走那么远!
希望大家能帮帮我!
感谢您阅读本文!
AQL 非常强大,但它不是 JavaScript,不支持您尝试使用的语法。
为了实现您的目标,您可以按下述方式使用 AQL。请注意 -
curl
,这使得它更简单,并且还提供使用 AQL 删除文件的功能(请参阅下面的注释)给定一个存储库,查找存储库中的所有文件夹:
items.find({"repo":"my-repo","type":"folder"}).include("repo","path","name")
结果:
{
"results" : [ {
"repo" : "my-repo",
"path" : "some/path",
"name" : "foo"
}, ...
],
"range" : { ... }
}
注释-
"repo":{"$match":"*"}
),但一般来说,最好将搜索重点放在精确匹配(即相等)上。对于步骤 1 中的每个文件夹 - 找到文件夹中的文件,按
created
时间降序排序(可以改为按 modified
排序)。
items.find({"repo":"my-repo","path":"some/path/foo","type":"file"}).include("repo","path","name","created").sort({"$desc":["created"]})
结果:
{
"results" : [ {
"repo" : "my-repo",
"path" : "some/path/foo",
"name" : "bar.txt",
"created" : "2023-09-04T10:40:58.737Z"
}, {
"repo" : "my-repo",
"path" : "some/path/foo",
"name" : "baz.txt",
"created" : "2023-09-04T10:35:43.274Z"
}, ... ],
"range" : { ... }
}
对于每个文件夹 - 保留前 10 个文件,其他所有文件都可以删除。
使用 JFrog CLI,您可以将上述步骤更改为 -