Search code examples
laravellaravel-5.1laravel-envoy

Laravel Envoy: abort on error


Is it possible to abort on errors or call another task when a command fails?

This doesn't work:

@task('migrate', ['on' => 'web'])
    cd {{ $currentReleaseDir }};
    php artisan migrate || exit 1;
@endtask

It fails with the message (I know I can run --force, it's just a way to make the command fail for testing):

**************************************
*     Application In Production!     *
**************************************

But then it proceeds to run the rest of the deploy script.


Solution

  • Yes, you can use:

    @error
       echo $task;
       exit; /*Or Do any other processing*/
    @enderror
    

    this outputs

    <?php $__container->error(function($task) {
        echo $task;
        exit; /*Or Do any other processing*/
    }); ?>
    

    This is listed in the compiler functions here https://github.com/laravel/envoy/blob/master/src/Compiler.php