From 35f3e307f35ba0882d0a64c7a218cc64e89bb8fb Mon Sep 17 00:00:00 2001 From: Timothy Rule <34501912+trulede@users.noreply.github.com> Date: Fri, 12 Sep 2025 21:24:26 +0200 Subject: [PATCH] Pass task vars to deferred tasks. --- task.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/task.go b/task.go index fc3f17662d..78a442d64d 100644 --- a/task.go +++ b/task.go @@ -211,7 +211,7 @@ func (e *Executor) RunTask(ctx context.Context, call *Call) error { for i := range t.Cmds { if t.Cmds[i].Defer { - defer e.runDeferred(t, call, i, &deferredExitCode) + defer e.runDeferred(t, call, i, t.Vars, &deferredExitCode) continue } @@ -278,17 +278,11 @@ func (e *Executor) runDeps(ctx context.Context, t *ast.Task) error { return g.Wait() } -func (e *Executor) runDeferred(t *ast.Task, call *Call, i int, deferredExitCode *uint8) { +func (e *Executor) runDeferred(t *ast.Task, call *Call, i int, vars *ast.Vars, deferredExitCode *uint8) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - origTask, err := e.GetTask(call) - if err != nil { - return - } - cmd := t.Cmds[i] - vars, _ := e.Compiler.GetVariables(origTask, call) cache := &templater.Cache{Vars: vars} extra := map[string]any{}