詹金斯 - 失败的测试

时间:2013-07-30 01:17:11

标签: git bash shell jenkins

在我的Jenkins测试中(只是shell),我想检查一个命令的存在状态(在这种情况下,它是git remote的存在):

git ls-remote some_remote
status=$?
if [ $status -ne 0 ]; then
  git remote add some_remote some@gitrepo.git
fi

但是,如果remote不存在,则第一个命令返回非零退出状态,测试失败而不再继续。

有办法吗?

2 个答案:

答案 0 :(得分:1)

另一种方式:

git ls-remote some_remote || status=$?
if [ $status -ne 0 ]; then
  git remote add some_remote some@gitrepo.git
fi

这样,第一行将始终返回true,您仍然可以捕获ls-remote的状态。

答案 1 :(得分:0)

用于远程的grep配置文件,并根据grep的零或非零状态采取必要的操作