artifactory - 如何通过 REST API 删除本地 Artifactory 存储库的所有内容?
问题描述
我正在使用本地存储库作为临时存储库,并希望能够通过 REST 清除整个临时存储库。如何在不删除 repo 本身的情况下删除 repo 的内容?
解决方案
由于我在我的一个环境中有类似的要求,我喜欢提供一种可能的解决方案。
假设 JFrog Artifactory 实例有一个名为的本地存储库JFROG-ARTIFACTORY
,其中包含最新的 JFrog Artifactory Pro 安装 RPM。对于列出和删除,我创建了以下脚本:
#!/bin/bash
# The logged in user will be also the admin account for Artifactory REST API
A_ACCOUNT=$(who am i | cut -d " " -f 1)
LOCAL_REPO=$1
PASSWORD=$2
STAGE=$3
URL="example.com"
# Check if a stage were provided, if not set it to PROD
if [ -z "$STAGE" ]; then
STAGE="repository-prod"
fi
# Going to list all files within the local repository
# Doc: https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-FileList
curl --silent \
-u"${A_ACCOUNT}:${PASSWORD}" \
-i \
-X GET "https://${STAGE}.${URL}/artifactory/api/storage/${LOCAL_REPO}/?list&deep=1" \
-w "\n\n%{http_code}\n"
echo
# Going to delete all files in the local repository
# Doc: https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-DeleteItem
curl --silent \
-u"${A_ACCOUNT}:${PASSWORD}" \
-i \
-X DELETE "https://${STAGE}.${URL}/artifactory/${LOCAL_REPO}/" \
-w "\n\n%{http_code}\n"
echo
所以打电话后
./Scripts/deleteRepository.sh JFROG-ARTIFACTORY Pa\$\$w0rd! repository-dev
对于开发实例,它列出了本地存储库中名为JFROG-ARTIFACTORY
JFrog Artifactory Pro 安装 RPM 的所有文件,删除了它们,但保留了本地存储库本身。
您可以根据需要更改和增强脚本,还可以查看如何从 Artifactory 中完全删除工件?
推荐阅读
- mysql - 如何查看 MySQL 中列的 utf8mbf 排序规则?
- php - Laravel 自定义商店方法无法正常工作
- c++ - 如何覆盖派生类中的虚函数?
- spring-security - Spring Security OAuth2 redirect_uri 回调导致 404
- c - 为什么字符串中包含的空格不起作用?
- android - 在listview android中快速滚动时崩溃
- android - 如何在保留在主屏幕上的小部件中打开另一个视图?
- linux - linux exit 1 vs false 命令之间的区别
- html - 在自动正确调整大小之前,轮播图像最初显示太小
- raspberry-pi - 树莓派 - canbus can-utils 超时?