GoogleContainerTools/skaffold · error

unable to evaluate cli flags: %w

Error message

unable to evaluate cli flags: %w

What it means

When building the `docker build` argument list, each entry of the artifact's CliFlags is expanded with util.ExpandEnvTemplate, substituting environment variables into the user-provided flag string. If a flag references an undefined or malformed template variable, the error is wrapped as "unable to evaluate cli flags: %w". This is a configuration error in the skaffold artifact definition, not a Docker problem.

Source

Thrown at pkg/skaffold/docker/image.go:691

		if v == nil {
			args = append(args, k)
		} else {
			args = append(args, fmt.Sprintf("%s=%s", k, *v))
		}
	}

	for _, host := range a.AddHost {
		args = append(args, "--add-host", host)
	}

	for _, from := range a.CacheFrom {
		args = append(args, "--cache-from", from)
	}

	for _, cliFlag := range a.CliFlags {
		cliFlag, err := util.ExpandEnvTemplate(cliFlag, env)
		if err != nil {
			return nil, fmt.Errorf("unable to evaluate cli flags: %w", err)
		}
		args = append(args, cliFlag)
	}

	if a.Target != "" {
		args = append(args, "--target", a.Target)
	}

	if a.NetworkMode != "" {
		args = append(args, "--network", strings.ToLower(a.NetworkMode))
	}

	if a.NoCache {
		args = append(args, "--no-cache")
	}

	if a.Squash {
		args = append(args, "--squash")

View on GitHub (pinned to a1189de023)

Solutions

  1. Export the referenced environment variable before running skaffold (`export MY_VAR=...`).
  2. Fix the variable name in the skaffold.yaml cliFlags — check for typos against the actual env.
  3. Remove invalid template syntax from the flag string (stray `{{`/`}}`).
  4. Provide a default in the flag value or set the variable in CI pipeline configuration.

Example fix

// before (skaffold.yaml)
cliFlags: ["--build-arg", "TOKEN={{.MISSING_TOKEN}}"]
// after
cliFlags: ["--build-arg", "TOKEN={{.TOKEN}}"]
# with: export TOKEN=abc123
Defensive patterns

Strategy: validation

Validate before calling

// expand the same templates locally before invoking the build
for _, f := range artifact.CliFlags {
    if _, err := util.ExpandEnvTemplate(f, env); err != nil {
        return fmt.Errorf("cli flag %q needs env vars that are unset: %w", f, err)
    }
}

Prevention

When it happens

Trigger: A build artifact's `cliFlags` (dockerfile buildArgs section) contains an env-template like `{{.MY_VAR}}` or `$MY_VAR` where MY_VAR is unset in the environment, or the template syntax itself is invalid.

Common situations: CI environment missing a variable that exists locally, typo in the variable name inside cliFlags, leftover `{{` syntax from copy-paste, variable only defined in a shell profile that the skaffold process doesn't inherit.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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