失败后继续耙

时间:2012-02-28 19:30:18

标签: ruby nunit rake cruisecontrol.net

我正在运行rake来自动化我在CCNet内部的构建过程。我用它来启动IIS Express,然后运行Nunit,然后在Nunit完成后关闭服务器。问题是,每次Nunit失败,耙子停止,永远不会到达关闭部分。在Nunit失败后如何继续使用rake,并且仍然告诉CCNet Nunit失败了,构建也是如此?

2 个答案:

答案 0 :(得分:6)

你如何从rake运行NUnit?你在用“sh”吗?

这是使用“sh”执行shell命令并拦截结果的方法。

我只是使用空块来忽略任何结果(失败或成功)

            sh "your shell command" do |ok,res|
                #empty block to ignore any failed or success status
                #in your case set failed flag based on ok parameter
               nunitSuccessFlag=false #hardcoded for sample; must set true or false based on ok parameter
            end
关闭服务器后,

将此引发异常置于ccnet知道构建失败

    raise "NUnit failed" if nunitSuccessFlag == false

替代方法:使用上面用户knut所述的try catch块,如以下链接所示:         Rake Task: error handling(关闭确保块中的服务器)

答案 1 :(得分:4)

我用它来使rake忽略从命令返回的状态:

sh "the command || true"

true始终退出而不会出现错误,使sh始终看到成功。