【问题标题】:How to add git remote repos name repeatedly in jenkins shell?如何在 jenkins shell 中重复添加 git 远程仓库名称?
【发布时间】:2013-06-14 13:33:47
【问题描述】:

在jenkins shell中,我想添加远程仓库,但是如果仓库名称存在,那么我遇到了

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

【问题讨论】:

    标签: git shell jenkins


    【解决方案1】:

    使用此脚本,您将确认来源列表是否将 I-WANT*.git 作为可推送资源

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

    【讨论】:

      【解决方案2】:

      我的解决方法,我在下面检查:

      Wipe out workspace before build
      

      永远

      git remote add pushable
      

      【讨论】:

        【解决方案3】:

        简单而懒惰的解决方案:P

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

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

        【讨论】:

          猜你喜欢
          • 2013-02-07
          • 1970-01-01
          • 1970-01-01
          • 2013-08-05
          • 2014-09-27
          • 2021-04-07
          • 2018-01-24
          • 1970-01-01
          • 2011-11-26
          相关资源
          最近更新 更多