Bealer
Bealer

Reputation: 864

Rake (Ruby) catch error at end of build

I'm using Ruby and Rake to do our builds at the moment for .Net projects.

I call a few commandline tools, such as NCover to check the coverage is high enough. When NCover returns and exit (fail) code though, Rake exits immediately stops.

Is there a hook, like on_exit, that I can use. I basically want to output "Build FAILED" in nice red writing, and if possible the step it failed on, and even better a message as to why. Just so it's a little clearer to the devs.

There is something similar in NAnt, and it's quite handy. Wondering if Rake/Ruby had anything similar.

Anyone had any experience with this sort of thing?

Cheers.

Upvotes: 2

Views: 583

Answers (2)

Geo
Geo

Reputation: 96867

Ruby has at_exit. You can use it like this:

at_exit do
   puts "this gets printed before the script finishes"
end

Upvotes: 3

Vincent
Vincent

Reputation: 4933

Maybe you can check for the error returned by the tool like this:

sh %{NCover file} do |ok, res|
  if ! ok
    raise "Build FAILED in NCover"
  end
end

Upvotes: 1

Related Questions