Continue Rake after failure
Asked Answered
A

2

6

I'm running rake to automate my build process inside of CCNet. I use it to start IIS Express, then run Nunit, and then shutdown the server after Nunit has finished. The problem is that every time Nunit fails, the rake stops, and never gets to the shutdown part. How do I continue a rake after Nunit has failed, and still tell CCNet that Nunit has failed, and thus so has the build?

Asbury answered 28/2, 2012 at 19:30 Comment(1)
How does rake stop? Is there an exception? If yes - catch it.Krouse
B
6

How do you run NUnit from rake? are you using "sh"?

This is how you use "sh" to execute shell command, and intercept the result.

I just use empty block to ignore any result(failed or success)

            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

put this raise exception after shutting down the server so ccnet knows that build failed

    raise "NUnit failed" if nunitSuccessFlag == false

alternative: use try catch block as stated by user knut above as shown in this link: Rake Task: error handling (shut down the server in the ensure block)

Briefs answered 29/2, 2012 at 4:39 Comment(0)
C
5

I used this to make rake ignore the status returned from the command:

sh "the command || true"

true always exits without an error, making sh always see a success.

Caliber answered 19/6, 2015 at 21:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.