GoogleContainerTools/skaffold · error

unable to get value for key

Error message

unable to get value for key %q: %w

What it means

EvaluateEnvTemplateMapWithEnv expands every map value as an env template against the given env map. This error means one value (identified by key k) failed ExpandEnvTemplate — either bad template syntax or a bad value — and it aborts evaluating the whole map. The key name and inner error are wrapped.

Solutions

  1. Check the specific key named in the error and fix its template syntax in skaffold.yaml.
  2. Ensure Go-template syntax {{.KEY}} rather than shell ${KEY} or {{KEY}}.
  3. Test the value standalone: util.ExpandEnvTemplate(value, os.Environ-as-map).
  4. Run 'skaffold diagnose' to surface all template issues at once.

Example fix

// before
buildArgs:
  TAG: {{.GIT_TAG
// after
buildArgs:
  TAG: "{{.GIT_TAG}}"
Defensive patterns

Strategy: validation

Validate before calling

for k, v := range m {
    if v != nil && !isValidEnvTemplate(*v) {
        return fmt.Errorf("key %q has invalid template %q", k, *v)
    }
}

Type guard

func allValuesAreValidTemplates(m map[string]*string) bool {
    for _, v := range m {
        if v != nil && !isValidEnvTemplate(*v) { return false }
    }
    return true
}

Try / catch

evaled, err := util.EvaluateEnvTemplateMap(m)
if err != nil {
    // error message names the offending key via %q
    var key string
    fmt.Sscanf(err.Error(), "unable to get value for key %q", &key)
    return fmt.Errorf("fix template under key %s", key)
}

Prevention

When it happens

Trigger: ExpandEnvTemplate(*v, env) errors for a key in the map: value contains invalid {{...}} syntax (e.g. build args like '{{.FOO' with a missing brace) or ParseEnvTemplate rejects the string.

Common situations: skaffold.yaml buildArgs / artifacts fields where one entry has malformed Go-template syntax; mixing ${VAR} shell syntax where {{.VAR}} is expected; values copied from Helm charts with different templating engines.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/ebad83f824c3dfa7. Report an issue: GitHub.

Appendix: source

Thrown at pkg/skaffold/util/env_template.go:106

	return EvaluateEnvTemplateMapWithEnv(args, nil)
}

// EvaluateEnvTemplateMapWithEnv parses and executes all map values as templates based on OS and custom environment variables
func EvaluateEnvTemplateMapWithEnv(args map[string]*string, env map[string]string) (map[string]*string, error) {
	if args == nil {
		return nil, nil
	}

	evaluated := map[string]*string{}
	for k, v := range args {
		if v == nil {
			evaluated[k] = nil
			continue
		}

		value, err := ExpandEnvTemplate(*v, env)
		if err != nil {
			return nil, fmt.Errorf("unable to get value for key %q: %w", k, err)
		}

		evaluated[k] = &value
	}

	return evaluated, nil
}

// MapToFlag parses all map values and returns them as `key=value` with the given flag
// Example: --my-flag key0=value0 --my-flag key1=value1  --my-flag key2=value2
func MapToFlag(m map[string]*string, flag string) ([]string, error) {
	kv, err := EvaluateEnvTemplateMap(m)
	if err != nil {
		return nil, fmt.Errorf("unable to evaluate build args: %w", err)
	}

	var keys []string
	for k := range kv {

View on GitHub (pinned to a1189de023)