mirror of
https://github.com/go-task/task.git
synced 2025-11-23 22:24:45 +02:00
feat(defer): expose EXIT_CODE special variable to defer: (#1762)
Co-authored-by: Dor Sahar <dorsahar@icloud.com>
This commit is contained in:
@@ -117,6 +117,7 @@ special variable will be overridden.
|
||||
| `TIMESTAMP` | The date object of the greatest timestamp of the files listed in `sources`. Only available within the `status` prop and if method is set to `timestamp`. |
|
||||
| `TASK_VERSION` | The current version of task. |
|
||||
| `ITEM` | The value of the current iteration when using the `for` property. Can be changed to a different variable name using `as:`. |
|
||||
| `EXIT_CODE` | Available exclusively inside the `defer:` command. Contains the failed command exit code. Only set when non-zero. |
|
||||
|
||||
## Functions
|
||||
|
||||
|
||||
@@ -1520,6 +1520,20 @@ commands are executed in the reverse order if you schedule multiple of them.
|
||||
|
||||
:::
|
||||
|
||||
A special variable `.EXIT_CODE` is exposed when a command exited with a non-zero
|
||||
exit code. You can check its presence to know if the task completed successfully
|
||||
or not:
|
||||
|
||||
```yaml
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
cmds:
|
||||
- defer: echo '{{if .EXIT_CODE}}Failed with {{.EXIT_CODE}}!{{else}}Success!{{end}}'
|
||||
- exit 1
|
||||
```
|
||||
|
||||
## Help
|
||||
|
||||
Running `task --list` (or `task -l`) lists all tasks with a description. The
|
||||
|
||||
Reference in New Issue
Block a user