我正在使用本地存储库作为暂存库,并希望能够通过REST清除整个暂存库。如何在不删除存储库的情况下删除存储库的内容?
发布于 2020-05-19 19:10:38
由于我在其中一个环境中有类似的需求,因此我想提供一种可能的解决方案方法。
假设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 installation RPM(s),删除了它们,但保留了本地存储库本身。
您可以根据需要更改和增强脚本,还可以查看How can I completely remove artifacts from Artifactory?
https://stackoverflow.com/questions/61680356
复制相似问题