如何在ARTIFACTORY中找到一个文件夹下工件的累积大小和总数
在Artifactory UI中,可以很容易地获得文件夹工件的大小和数量,但是,没有直接的REST API来获取这些信息。通过结合REST调用,我们可以通过多种方式实现这个用例文件列表终点如下:
→获取一个文件夹下的工件总数(例如:hello-world):$ curl -uadmin:密码“http://localhost:8081/artifactory/api/storage/docker-local/hello-world?”List&deep =1" -s | jq -c '[.files[]。Uri: | length'
→获取该路径下工件的累积大小(以字节为单位)(例如:docker-local/hello-world):$ curl -uadmin:密码“http://localhost:8081/artifactory/api/storage/docker-local/hello-world?”List&deep =1" -s | jq -c '[.files[]。Size] | add' | numfmt -to=iec
此外,我们可以使用下面的脚本和AQL查询来打印存储库的每个文件夹大小,并可以根据用例扩展此脚本。
$ cat folderSizeAtRepositoryLevel.sh# !/bin/bash
curl -s -k -H 'Content-Type:text/plain' -uadmin:password -XPOST "/artifactory/api/search/aql" -d 'item .find({"type":"folder","repo":"docker-local","depth":1})' | grep "name" | awk '{print $3}' | sed 's/"//g' | sed 's/,//g' | awk 'length > 1' > folders.txt
对于$(cat folders.txt)中的文件夹;
做
返回“文件夹大小——>”$ Folder
curl -X POST -H "Content-Type:application/json" -uadmin:password "//artifactory/ui/artifactgeneral/artifactsCount?美元no_spinner = true”- d '{“名称”:“”文件夹“美元”,“repositoryPath”:“docker-local /美元文件夹“/”}”
printf“\ n”
完成