Hi
Thanks for all the answers.

What I was unclear about is the relationship between the unix command
line exit status and the success status of the task. It now seems
clear that if the the command succeeds the task succeeds and vice
versa.

This leads me on to another question. Should you generally encapsulate
only one external command in a capistrano task, or can I have an if
statement in my task that acts on the success/failure(true/false) of
the command line.  I will illustrate by a simple example.

 if run "dosomething" then do task1
 else first do task 2

and to clarify what I meant in my previous email I would also like to
do the following:
task
  result = (run "command")
  if result = 'a piece of string' then fail task immediatly to trigger
rollback
end

Regards

On Jan 21, 6:07 pm, Jamis Buck <[email protected]> wrote:
> What Rafael said, except if you're rescuing the exception you should be
> able to leave off the :on_error => :continue bit.
>
> Also, to force a task to succeed or fail...I assume you mean run()? Or
> do you really mean task()?
>
> To force a run command to succeed, just append "; true" to the end of
> the command:
>
>   run "something that might fail; true"
>
> Likewise, to make it fail, just append "; false" to the end:
>
>   run "something that must fail; false"
>
> (That's not Capistrano magic, that's *nix. Most (all?) unices come with
> 'true' and 'false' commands. The 'true' command does nothing except exit
> with a status code of 0. The 'false' command does nothing except exit
> with a status code of 1.)
>
> - Jamis
>
> On 1/21/09 10:42 AM, Rafael G. wrote:
>
> > Gerhardus Geldenhuis wrote:
> >> Hi
> >> Is there a way to run different tasks based on the exit status of a
> >> run command? Also how can I "force" a task to fail or succeed, how is
> >> the failure/success of a task determined/defined.
>
> >> Regards
>
> > You can write a task with :on_error set to :continue and then catch the
> > exception, I never done it, the idea is:
> >   task :foo, :on_error => :continue do
> >     begin
> >       run "important task"
> >     rescue Exception => error
> >       puts "Important task fail!!: #{error}"
> >       foo.task_if_foo_fail
> >     end
> >   end
--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---

Reply via email to