How to explicitly fail a task in ruby rake?

Use the raise or fail method as you would for any other Ruby script (fail is an alias for raise). This method takes a string or exception as an argument which is used as the error message displayed at termination of the script. This will also cause the script to return the value 1 to the calling shell. It is documented here and other places.


You can use abort("message") to gracefully fail rake task.

It will print message to stdout and exit with code 1.

Exit code 1 is a failure in Unix-like systems.

See Kernel#abort for details.