22
Oct '13

After a long break from doing anything with Ruby (On Rails or otherwise) I’ve had cause to get my head back into Capistrano lately and am really enjoying it, however it’s fair to say that documentation, particularly for deploying anything other than Ruby apps, is rather lacking.
The biggest difficulty I has was in making the script exit cleanly if a branch / tag was specified that doesn’t exist. The update logic was so wrapped up in the core of Capistrano that I had a devil of a time tracking it down. So, for all who have a similar problem, here is the solution I found:

desc 'Update the code and fail cleanly if branch not found'
task :update do
 transaction do
  begin
   update_code
  rescue
   puts "Branch / Tag not found"
   exit
  end
 end

 create_symlink
end

What I am doing is simply overriding the core ‘deploy:update’ task and recreating it with a begin-rescue around the ‘update_code’ call. Happy days.