Closed bkis closed 1 year ago
@bkis You should be able to use the defer
keyword for your use case (or any scenario where you require some form of clean up):
version: '3'
tasks:
start-services:
cmds:
- echo Starting services...
stop-services:
cmds:
- echo Stopping services...
run-tests:
cmds:
- echo Running app...
- exit 1
test:
cmds:
- defer: {task: stop-services}
- task: start-services
- task: run-tests
Please let us know if this works for you or not.
It does, thank you! I guess for me it wasn't clear from the documentation that defer
ed commands will run no matter what:
Alternative to
cmd
, but schedules the command to be executed at the end of this task instead of immediately. This cannot be used together withcmd
.
...is all it says.
But yes, this completely does what I need. Thank you!
Let's say I have the following
Taskfile.yml
:The
test
task runs three other tasks in sequence (as this is important here, I'm not using preconditions):start-services
starts services needed by the (integration) test suiterun-tests
runs the test suite (which fails for demonstration purposes)stop-services
tears down all services etc...The result:
Now I naturally want to always execute
stop-services
(which doesn't happen in the example above), even if my tests fail. To achieve that, I addignore_error
to therun-tests
task:The result:
That's cool - it stops my testing services now. But the whole task (
test
) now exits with code0
although my tests failed. It would be nice if I could configure it to somehow exit with a non-zero exit code if any sub-task failed even if errors are ignored.I see two ways to do that:
ignore_error
(e.g.on_error: 101
would allow to set the specific code to use, orfail_on_error: true
, you get it...). But that would be not very intuitive, I think. A much better one would be this:force_run: true
. Tasks withforce_run: true
would then always be run whenever it's their "turn" - nothing else would have to change. Task would just have to check whether there are subsequent tasks after the failing one that have this option set and run them normally. The overall ("parent"?) task should still exit with a non-zero code then.