diff --git a/task.go b/task.go index 40f7661a..01dccc13 100644 --- a/task.go +++ b/task.go @@ -297,6 +297,8 @@ func (e *Executor) runDeferred(t *ast.Task, call *Call, i int, deferredExitCode } cmd.Cmd = templater.ReplaceWithExtra(cmd.Cmd, cache, extra) + cmd.Task = templater.ReplaceWithExtra(cmd.Task, cache, extra) + cmd.Vars = templater.ReplaceVarsWithExtra(cmd.Vars, cache, extra) if err := e.runCommand(ctx, t, call, i); err != nil { e.Logger.VerboseErrf(logger.Yellow, "task: ignored error in deferred cmd: %s\n", err.Error()) diff --git a/task_test.go b/task_test.go index a2400cd3..73fa285b 100644 --- a/task_test.go +++ b/task_test.go @@ -1809,6 +1809,9 @@ task-1 ran successfully `) require.Error(t, e.Run(context.Background(), &task.Call{Task: "task-2"})) assert.Contains(t, buff.String(), expectedOutputOrder) + buff.Reset() + require.NoError(t, e.Run(context.Background(), &task.Call{Task: "parent"})) + assert.Contains(t, buff.String(), "child task deferred value-from-parent") } func TestExitCodeZero(t *testing.T) { diff --git a/testdata/deferred/Taskfile.yml b/testdata/deferred/Taskfile.yml index b193117c..9ea3d0aa 100644 --- a/testdata/deferred/Taskfile.yml +++ b/testdata/deferred/Taskfile.yml @@ -12,3 +12,18 @@ tasks: - defer: echo 'failing' && exit 2 - echo 'cmd ran' - exit 1 + + parent: + vars: + VAR1: "value-from-parent" + cmds: + - defer: + task: child + vars: + VAR1: 'task deferred {{.VAR1}}' + - task: child + vars: + VAR1: 'task immediate {{.VAR1}}' + child: + cmds: + - cmd: echo "child {{.VAR1}}"