Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func (c *Compiler) getVariables(t *ast.Task, call *Call, evaluateShVars bool) (*
return nil, err
}
}
// Resolve any outstanding 'Ref' values in global vars (esp. globals from imported Taskfiles).
c.TaskfileVars = templater.ReplaceVars(c.TaskfileVars, &templater.Cache{Vars: result})

if t != nil {
for k, v := range t.IncludeVars.All() {
if err := rangeFunc(k, v); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,10 @@ func TestReference(t *testing.T) {
name: "reference using templating resolver and dynamic var",
call: "ref-resolver-sh",
},
{
name: "reference using templating resolver and global var",
call: "ref-global",
},
}

for _, test := range tests {
Expand Down
14 changes: 14 additions & 0 deletions testdata/var_references/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ version: '3'

vars:
GLOBAL_VAR: [1, 2, 2, 2, 3, 3, 4, 5]
GLOBAL_FOO:
ref: .GLOBAL_BAR
GLOBAL_BAR: bar

tasks:
default:
- task: ref-cmd
- task: ref-dep
- task: ref-resolver
- task: ref-resolver-sh
- task: ref-global

ref-cmd:
vars:
Expand Down Expand Up @@ -72,3 +76,13 @@ tasks:
{{- else}} and {{$child.name -}}
{{- end -}}
{{- end -}}"

ref-global:
vars:
TASK_FUBAR:
ref: .GLOBAL_FOO
cmds:
- echo "GLOBAL_FOO={{.GLOBAL_FOO}}"
- echo "GLOBAL_BAR={{.GLOBAL_BAR}}"
- echo "TASK_FUBAR={{.TASK_FUBAR}}"
silent: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GLOBAL_FOO=bar
GLOBAL_BAR=bar
TASK_FUBAR=bar
Loading