GoogleContainerTools/skaffold · error

unable to evaluate build args: %w

Error message

unable to evaluate build args: %w

What it means

After parsing the tag, Build evaluates the artifact's Docker build args (including env-var interpolation and extra build args) via EvalBuildArgsWithEnv. If any buildarg value cannot be evaluated — for example because it references an unset environment variable in requires-env mode or is malformed — the build fails before the context is created.

Source

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

		return fmt.Errorf("docker build options, secrets and ssh, require BuildKit - set `useBuildkit: true` in your config, or run with `DOCKER_BUILDKIT=1`")
	}
	return nil
}

// Build performs a docker build and returns the imageID.
func (l *localDaemon) Build(ctx context.Context, out io.Writer, workspace string, artifact string, a *latest.DockerArtifact, opts BuildOptions) (string, error) {
	log.Entry(ctx).Debugf("Running docker build: context: %s, dockerfile: %s", workspace, a.DockerfilePath)

	if err := l.CheckCompatible(a); err != nil {
		return "", err
	}
	imageInfoEnv, err := EnvTags(opts.Tag)
	if err != nil {
		return "", fmt.Errorf("couldn't parse image tag: %w", err)
	}
	buildArgs, err := EvalBuildArgsWithEnv(opts.Mode, workspace, a.DockerfilePath, a.BuildArgs, opts.ExtraBuildArgs, imageInfoEnv)
	if err != nil {
		return "", fmt.Errorf("unable to evaluate build args: %w", err)
	}

	// Like `docker build`, we ignore the errors
	// See https://github.com/docker/cli/blob/75c1bb1f33d7cedbaf48404597d5bf9818199480/cli/command/image/build.go#L364
	authConfigs, _ := DefaultAuthHelper.GetAllAuthConfigs(ctx)

	buildCtx, buildCtxWriter := io.Pipe()
	go func() {
		err := CreateDockerTarContext(ctx, buildCtxWriter,
			NewBuildConfig(workspace, artifact, a.DockerfilePath, buildArgs), l.cfg)
		if err != nil {
			buildCtxWriter.CloseWithError(fmt.Errorf("creating docker context: %w", err))
			return
		}
		buildCtxWriter.Close()
	}()

	progressOutput := progress.NewProgressOutput(out)

View on GitHub (pinned to a1189de023)

Solutions

  1. Ensure every environment variable referenced by build args is set in the build environment
  2. Fix the buildArgs entries in skaffold.yaml for typos or invalid template syntax
  3. Pass missing values via skaffold's --default-repo/--build-arg style flags or opts.ExtraBuildArgs
  4. Read the wrapped inner error (%w) to identify exactly which build arg failed

Example fix

// before (skaffold.yaml)
build:
  artifacts:
    - image: app
      docker:
        buildArgs:
          VERSION: "{{.APP_VERSION}}"
// after (export the var first, or hardcode)
export APP_VERSION=1.2.3
# or
buildArgs:
  VERSION: "1.2.3"
Defensive patterns

Strategy: validation

Validate before calling

for k, v := range buildArgs {
	if strings.HasPrefix(v, "{{") {
		// ensure every referenced env var exists before building
		if err := verifyTemplateVars(v, os.Environ()); err != nil {
			return fmt.Errorf("build arg %s: %w", k, err)
		}
	}
}

Try / catch

imageID, err := daemon.Build(...)
if err != nil && strings.Contains(err.Error(), "unable to evaluate build args") {
	return fmt.Errorf("check buildArgs/env in config: %w", err)
}

Prevention

When it happens

Trigger: Calling localDaemon.Build where a.DockerfilePath's artifact a.BuildArgs contain entries EvalBuildArgsWithEnv cannot resolve given opts.Mode, opts.ExtraBuildArgs, and imageInfoEnv — e.g. a build arg defined with an env value that is unset, or invalid buildarg syntax.

Common situations: skaffold.yaml declares `buildArgs: {FOO: "{{.MY_VAR}}"}` but MY_VAR is not exported; build args require env vars that exist locally but not in CI; mismatch between BuildMode and available values (e.g. requiring all args be provided via CLI).

Related errors


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