2013-11-21 36 views
2

我有一個項目,裏面藏有大約30個存儲庫。我擺弄他們一下,現在我想重置一切,然後重新導入它們。據我所知,沒有辦法「清理」Stash中的存儲庫,所以我決定刪除它們並重新創建它們。由於存在一堆存儲庫,這可能不是我最後一次這樣做,所以我會非常感謝一次刪除/創建多個存儲庫的方式,因爲我需要相當長的時間通過前端手動完成此操作。有誰知道,如果可能的話?在Atlassian Stash中立即刪除多個存儲庫

回答

2

把開發商藏在這裏。我沒有看到Marketplace上的插件會這樣做。一個簡單的bash腳本會使用我們的REST api嗎?

for path in 'projectA/repos/repoA' 'myprojectB/repos/myrepoB' 'somethingC/repos/somethingC'; do curl -X DELETE --user username:password http://host:port/rest/api/1.0/projects/$path; done 

或者類似的東西

+0

沒有看到你的答案,直到剛剛現在。我已經使用REST API編寫了perl腳本:)謝謝 – Vince

0

通過具有訪問您的藏匿/主機到位桶,我想出了下面的腳本一臺Linux機器:

#!/bin/bash 
USER='someUser' 
PASS='secretPassWord' 

sudo apt-get -qq install jq curl 
TMP=/tmp/PROJECTS.TO.DELETE.$RANDOM 

# Get a list of all Projects 
curl -k -s --user $USER:$PASS "https://stashHost/rest/api/1.0/projects/?limit=10000" | jq -r ".values[].key" | sort >$TMP 

# Allow an opertunity to remove some projects from this deletion process 
nano $TMP 

# Loop through the remaining projects listed in the $TMP file and remove all repo's and projects. 
for P in $(cat $TMP); do 
     echo "Project: $P" 
     for R in $(curl -k -s --user $USER:$PASS "https://stashHost/rest/api/1.0/projects/$P/repos?limit=10000" | jq -r ".values[].slug" | sort); 
     do 
       # Delete the repository 
       OUTPUT=`curl -k -s -X DELETE --user $USER:$PASS "https://stashHost/rest/api/1.0/projects/$P/repos/$R" | jq -r ".message"` 
       printf "Deleting: %10s\t%40s\t%s\n" $P $R "$OUTPUT" 
     done; 
     # Delete the empty project (with no remaining repos) 
     curl -k -s -X DELETE --user $USER:$PASS "https://stashHost/rest/api/1.0/projects/$P"; 
done;