GoogleContainerTools/skaffold · error

unable to evaluate build args: %w

Error message

unable to evaluate build args: %w

What it means

For a DockerArtifact, sourceDependenciesForArtifact evaluates the Dockerfile build args (with env expansion and dependency image values) via docker.EvalBuildArgsWithEnv before listing filesystem dependencies. If evaluation fails — typically because a build arg references an undefined env var or an invalid template — the error is wrapped as 'unable to evaluate build args'.

Source

Thrown at pkg/skaffold/graph/dependencies.go:134

		err   error
	)

	envTags, evalErr := docker.EnvTags(tag)
	if evalErr != nil {
		return nil, fmt.Errorf("unable to create build args: %w", err)
	}

	switch {
	case a.DockerArtifact != nil:
		// Required artifacts cannot be resolved when `ResolveDependencyImages` runs prior to a completed build sequence (like `skaffold build` or the first iteration of `skaffold dev`).
		// However it only affects the behavior for Dockerfiles with ONBUILD instructions, and there's no functional change even for those scenarios.
		// For single build scenarios like `build` and `run`, it is called for the cache hash calculations which are already handled in `artifactHasher`.
		// For `dev` it will succeed on the first dev loop and list any additional dependencies found from the base artifact's ONBUILD instructions as a file added instead of modified (see `filemon.Events`)
		deps := docker.ResolveDependencyImages(a.Dependencies, r, false)

		args, evalErr := docker.EvalBuildArgsWithEnv(cfg.Mode(), a.Workspace, a.DockerArtifact.DockerfilePath, a.DockerArtifact.BuildArgs, deps, envTags)
		if evalErr != nil {
			return nil, fmt.Errorf("unable to evaluate build args: %w", evalErr)
		}
		paths, err = docker.GetDependencies(ctx, docker.NewBuildConfig(a.Workspace, a.ImageName, a.DockerArtifact.DockerfilePath, args), cfg)

	case a.KanikoArtifact != nil:
		deps := docker.ResolveDependencyImages(a.Dependencies, r, false)
		args, evalErr := docker.EvalBuildArgsWithEnv(cfg.Mode(), kaniko.GetContext(a.KanikoArtifact, a.Workspace), a.KanikoArtifact.DockerfilePath, a.KanikoArtifact.BuildArgs, deps, envTags)
		if evalErr != nil {
			return nil, fmt.Errorf("unable to evaluate build args: %w", evalErr)
		}
		paths, err = docker.GetDependencies(ctx, docker.NewBuildConfig(kaniko.GetContext(a.KanikoArtifact, a.Workspace), a.ImageName, a.KanikoArtifact.DockerfilePath, args), cfg)

	case a.BazelArtifact != nil:
		paths, err = bazel.GetDependencies(ctx, a.Workspace, a.BazelArtifact)

	case a.JibArtifact != nil:
		paths, err = jib.GetDependencies(ctx, a.Workspace, a.JibArtifact)

	case a.CustomArtifact != nil:

View on GitHub (pinned to a1189de023)

Solutions

  1. Set the missing environment variable in the shell/CI environment or via skaffold.yaml `deploy`/`portForward` env configuration.
  2. Provide default values for the build args in the Dockerfile (`ARG MYVAR=default`) so evaluation succeeds without the env var.
  3. For ONBUILD-dependent args, ensure the referenced dependency artifacts are built first, or accept that the first dev loop skips them.
  4. Run with `-vdebug` to see the exact build arg and template that failed evaluation.

Example fix

// before (skaffold.yaml)
buildArgs: { MYVAR: '{{.UNSET_VAR}}' }
// after (default in Dockerfile or set the var)
// Dockerfile: ARG MYVAR=default
// or shell: export UNSET_VAR=value
Defensive patterns

Strategy: validation

Validate before calling

// Ensure every ${VAR} referenced in build args exists before calling Skaffold APIs
for _, v := range buildArgs {
	for _, m := range envVarPattern.FindAllStringSubmatch(v, -1) {
		if os.Getenv(m[1]) == "" {
			return fmt.Errorf("env var %s used in build args is unset", m[1])
		}
	}
}

Prevention

When it happens

Trigger: An artifact with `dockerArtifact` whose Dockerfile buildArgs (or dependency image placeholders) reference environment variables that don't exist in the Skaffold environment, or contain malformed `${VAR}`/`{{.VAR}}` templates, during dependency computation (dev loop or cache hashing).

Common situations: Dockerfile uses `ARG` filled from an env var missing in the shell/CI running Skaffold; build args interpolate images (`dependencies`) that haven't been built yet during the first dev loop; typos in Go template syntax in skaffold.yaml build args.

Related errors


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