Local task error or exit do not stop the script execution
Tofandel opened this issue · comments
Envoy Version
2.8.6
Laravel Version
10.25.0
PHP Version
8.1
Database Driver & Version
No response
Description
Script lines of local task's which are failing are completely ignored and continues the script execution, which is a different behavior than a task executed via ssh
Steps To Reproduce
@servers(['local' => 'localhost'])
@task('transfer', ['on' => 'local'])
foo
echo $?
(echo "test" && exit 1)
echo $?
echo "Oops"
@endtask
Output
vendor/bin/envoy run transfer
[localhost]: sh: 1: foo: not found
[localhost]: 127
[localhost]: test
[localhost]: 1
[localhost]: Oops
Only a direct exit 1;
outside of parentesis seems to stop the rest of the execution
So the workaround seems to be adding || exit $?
after each line in a script, or starting the local scripts with set -e
A possible fix would then be
$isWin = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
if (in_array($target, ['local', 'localhost', '127.0.0.1'])) {
$process = Process::fromShellCommandline($isWin ? $task->script : 'set -e'.PHP_EOL.$task->script, null, $env);
}
Thanks @Tofandel. Can you PR that change so Taylor can have a look?
Closing this issue because it's inactive, already solved, old or not relevant anymore. Feel to open up a new issue if you're still experiencing this.