在jenkins shell中,我想添加远程repos,但是如果存在repos名称,那么我遇到了
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://$GH_TOKEN@github.com/foo/bar.git
fi
然后我得到了:
++ grep pushable
++ git remote
+ o=
Build step 'Execute shell' marked build as failure
答案 0 :(得分: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
答案 1 :(得分:0)
我的解决方法,我在下面查看:
Wipe out workspace before build
始终
git remote add pushable
答案 2 :(得分:0)
简单而懒惰的解决方案:P
$ git push remote add I-WANT-TO-PUSH 2> /dev/null || echo
或
$ git push remote add I-WANT-TO-PUSH || echo