-
-
Notifications
You must be signed in to change notification settings - Fork 763
Open
Open
Copy link
Labels
area: variablesChanges related to variables.Changes related to variables.
Description
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:
- Generate the Taskfile :
# https://taskfile.dev
version: '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: exit
vars:
MESSAGE:
sh: "echo Defer to task via vars with sh {{if .EXIT_CODE}}Failed with {{.EXIT_CODE}}!{{else}}Success!{{end}}"
- defer:
task: exit
vars:
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 1Version
Task version: v3.40.1 (h1:Q/TjPh5SAI+XK2fBravDPZXNGm6mvnwrLJqCXfhZ3Wc=)
Operating system
Debian 12
Experiments Enabled
No response
Example Taskfile
# https://taskfile.dev
version: '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: exit
vars:
MESSAGE:
sh: "echo Defer to task via vars with sh {{if .EXIT_CODE}}Failed with {{.EXIT_CODE}}!{{else}}Success!{{end}}"
- defer:
task: exit
vars:
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 1Metadata
Metadata
Assignees
Labels
area: variablesChanges related to variables.Changes related to variables.