Question

I have a task that validates the integrity of the build that is about to be deployed.

I would like to halt/fail the deploy in case it's broken.

task :test_build do
  if something
    puts "Problem with build"
    #prevent deploy to continue further
  end
end
after('deploy:update_code', 'test_build')

Note: Project uses railsless-deploy

Was it helpful?

Solution

You should raise a CommandError exception:

error = CommandError.new("An error that should abort and rollback deployment") 
raise error

So no backtrace are shown.

OTHER TIPS

CommandError is no longer defined in Capistrano. Looking at other examples, I found that using puts statements describing the error followed by an exit call are being used. So just:

puts "Problem with build"
exit

As stated by @engineersmnky in the question's comments, raise "Error with build" will trigger a halt for the current deploy. But this solution print an ugly stack trace since it's not handled by Capistrano.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top