fix: interpolate a task file before it is parsed

A var used in container_limits broke the build, because FileConfigSource
parses the file into an atc.TaskConfig before any interpolation happens, and
'((container_mem_limit))' is not a memory limit. Only fields that are plain
strings survived that first parse.

FileConfigSource can now hand back the file as written, and
InterpolateTemplateConfigSource resolves those bytes and parses once,
instead of parsing, marshalling back and parsing again. For a task file the
interpolation pass now always runs, with the pipeline vars followed by the
credential variables, so a var resolves the same way wherever it appears in
the file.
This commit is contained in:
dualfroz committed 2026-09-13 15:29:51 +02:00
1 parent af4510fc7f
commit 10dad07bcd
4 files changed
+154 -24

No files matched your search

+11 -6
View File
@@ -169,13 +169,18 @@ func (step *TaskStep) run(ctx context.Context, state RunState, delegate TaskDele
taskConfigSource = FileConfigSource{ConfigPath: step.plan.ConfigPath, Streamer: step.streamer}
// for interpolation - use 'vars' from the pipeline, and then fill remaining with cred variables.
// this 2-phase strategy allows to interpolate 'vars' by cred variables.
// this pass reads the file as written, before it is parsed, so a var may
// stand in for a field that is not a string, such as container_limits.
configVars := []vars.Variables{}
if len(step.plan.Vars) > 0 {
taskConfigSource = InterpolateTemplateConfigSource{
ConfigSource: taskConfigSource,
Vars: []vars.Variables{vars.StaticVariables(step.plan.Vars)},
ExpectAllKeys: false,
}
configVars = append(configVars, vars.StaticVariables(step.plan.Vars))
}
configVars = append(configVars, state)
taskConfigSource = InterpolateTemplateConfigSource{
ConfigSource: taskConfigSource,
Vars: configVars,
ExpectAllKeys: false,
}
taskVars = []vars.Variables{state}
} else {