2013-06-18 54 views
2

在詹金斯外殼,我想補充的遠程回購,但回購是否存在名字,然後我遇到了如何在jenkins shell中重複添加git remote repos name?

fatal: remote I-WANT-TO-PUSH already exists. 

和詹金斯意外中止。

我想下面的僞代碼。

if [ ! git remote I-WANT-TO-PUSH exist? ] 
    git remote add I-WANT-TO-PUSH http://i-want-to-push.example.com 
fi 
git push I-WANT-TO-PUSH 

如何做到這一點?

編輯:(感謝@Nikolay)

下面

幾乎是實際代碼:

o=$(git remote | grep 'pushable') 
if [[ $o == '' ]]; then 
    hub remote add pushable https://[email protected]/foo/bar.git 
fi 

後來我:起源

++ grep pushable 
++ git remote 
+ o= 
Build step 'Execute shell' marked build as failure 

回答

0

我的解決方法,我在下面檢查:

Wipe out workspace before build 

始終

git remote add pushable 
2

有了這個腳本,你會做確認名單有I-WANT * .git作爲可壓縮資源

o=$(git remote -v| grep '/I-WANT-TO-PUSH.git (push)') 
if [[ $o == '' ]]; then 
echo "not exists" 
else 
echo "exist" 
fi 
0

容易和懶惰的解決方案:P

$ git push remote add I-WANT-TO-PUSH 2> /dev/null || echo 

$ git push remote add I-WANT-TO-PUSH || echo