我想自动化通过.json文件从另一个Artifactory导入现有存储库结构的过程。 到目前为止,我已经成功使用以下命令从json进行了单个回购。
curl -X PUT --insecure -u admin -H "Content-type: application/json" -T repository-config.json "https://artifactory.test.net/artifactory/api/repositories/acqbo-docker-release-local"
是否有一种方法可以从单个json文件和单个curl中导入多个/阵列的存储库?
答案 0 :(得分:0)
最终为此目的编写了自己的bash脚本。 您将必须使用要复制的存储库制作一个文件:
#!/bin/bash
#############
# This script copies the repository structure from one Artifactory server to another
# repos.list file is required to have repositories that we want to copy, each in new line.
# user with the admin rights is necessary
#############
#Where to copy repos from and to
ARTIFACTORY_SOURCE="https://source.group.net/artifactory/api/repositories/"
ARTIFACTORY_DESTINATION="https://destination.group.net/artifactory/api/repositories/"
NOLINES=$(wc -l < repos.list) #get total nuber of lines in repos.line
COUNTER=1 #Set the counter to 1
while [ $COUNTER -le $NOLINES ] #loops times number of lines in the repos.line
do
REPONAME=$(awk "NR==$COUNTER" repos.list) #get only repo name, line by line
curl -GET --insecure -u admin:adminpass "$ARTIFACTORY_SOURCE$REPONAME" > xrep.json #Obtain data from Artifactory source, repo by repo, and writes it to the xrep.json
curl -X PUT --insecure -u admin:adminpass -H "Content-type: application/json" -T xrep.json "$ARTIFACTORY_DESTINATION$REPONAME" #Sends data from json to the destination Artifactory server
#print in blue color
printf "\e[1;34m$COUNTER repo done\n\e[0m"
((COUNTER++))
done
printf "\e[1;34mAll repos exported!\n\e[0m"