You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to configure a task that is used in a defer based on the EXIT_CODE generated when a command fails in my Taskfile. However, I am encountering an issue where the EXIT_CODE variable is only available in a defer that uses a command directly, but not in a defer that references another task.
Steps to reproduce:
Generate the Taskfile :
# https://taskfile.devversion: '3'tasks:
exit:
cmd: echo {{.MESSAGE}}exit-with-exit-code:
cmd: echo Defer to task with EXIT_CODE management {{if .EXIT_CODE}}Failed with {{.EXIT_CODE}}!{{else}}Success!{{end}}exit-one:
cmds:
- defer:
task: exitvars:
MESSAGE:
sh: "echo Defer to task via vars with sh {{if .EXIT_CODE}}Failed with {{.EXIT_CODE}}!{{else}}Success!{{end}}"
- defer:
task: exitvars:
MESSAGE: "Defer to task via classic vars {{if .EXIT_CODE}}Failed with {{.EXIT_CODE}}!{{else}}Success!{{end}}"
- defer:
task: exit-with-exit-code
- defer: "echo 'Defer to cmd' {{if .EXIT_CODE}}Failed with {{.EXIT_CODE}}!{{else}}Success!{{end}}"
- | exit 1
Execute this command : task exit-one
This produces :
task: [exit-one] exit 1
task: [exit-one] echo'Defer to cmd' Failed with 1!
Defer to cmd Failed with 1!
task: [exit-with-exit-code] echo Defer to task with EXIT_CODE management Success!
Defer to task with EXIT_CODE management Success!
task: [exit] echo Defer to task via classic vars Success!
Defer to task via classic vars Success!
task: [exit] echo Defer to task via vars with sh Success!
Defer to task via vars with sh Success!
task: [exit-with-exit-code] echo Defer to task with EXIT_CODE management Success!
Defer to task with EXIT_CODE management Success!
task: Failed to run task "exit-one": exit status 1
But i expected :
task: [exit-one] exit 1
task: [exit-one] echo'Defer to cmd' Failed with 1!
Defer to cmd Failed with 1!
task: [exit-with-exit-code] echo Defer to task with EXIT_CODE management Failed with 1!
Defer to task with EXIT_CODE management Failed with 1!
task: [exit] echo Defer to task via classic vars Failed with 1!
Defer to task via classic vars Failed with 1!
task: [exit] echo Defer to task via vars with sh Failed with 1!
Defer to task via vars with sh Failed with 1!
task: [exit-with-exit-code] echo Defer to task with EXIT_CODE management Failed with 1!
Defer to task with EXIT_CODE management Failed with 1!
task: Failed to run task "exit-one": exit status 1
# https://taskfile.devversion: '3'tasks:
exit:
cmd: echo {{.MESSAGE}}exit-with-exit-code:
cmd: echo Defer to task with EXIT_CODE management {{if .EXIT_CODE}}Failed with {{.EXIT_CODE}}!{{else}}Success!{{end}}exit-one:
cmds:
- defer:
task: exitvars:
MESSAGE:
sh: "echo Defer to task via vars with sh {{if .EXIT_CODE}}Failed with {{.EXIT_CODE}}!{{else}}Success!{{end}}"
- defer:
task: exitvars:
MESSAGE: "Defer to task via classic vars {{if .EXIT_CODE}}Failed with {{.EXIT_CODE}}!{{else}}Success!{{end}}"
- defer:
task: exit-with-exit-code
- defer: "echo 'Defer to cmd' {{if .EXIT_CODE}}Failed with {{.EXIT_CODE}}!{{else}}Success!{{end}}"
- | exit 1
The text was updated successfully, but these errors were encountered:
I think if the EXIT_CODE was also added to the cmd.Vars at the same point; in the case when cmd.Vars is available, i.e. a Task and not a command; then probably this would work like you expect.
Description
I am trying to configure a task that is used in a defer based on the EXIT_CODE generated when a command fails in my Taskfile. However, I am encountering an issue where the EXIT_CODE variable is only available in a defer that uses a command directly, but not in a defer that references another task.
Steps to reproduce:
task exit-one
Version
Task version: v3.40.1 (h1:Q/TjPh5SAI+XK2fBravDPZXNGm6mvnwrLJqCXfhZ3Wc=)
Operating system
Debian 12
Experiments Enabled
No response
Example Taskfile
The text was updated successfully, but these errors were encountered: