{"record":{"id":"29926803d34fae4f","repo":"GoogleContainerTools/skaffold","slug":"unable-to-evaluate-build-args-w-299268","errorCode":null,"errorMessage":"unable to evaluate build args: %w","messagePattern":"unable to evaluate build args: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/graph/dependencies.go","lineNumber":134,"sourceCode":"\t\terr   error\n\t)\n\n\tenvTags, evalErr := docker.EnvTags(tag)\n\tif evalErr != nil {\n\t\treturn nil, fmt.Errorf(\"unable to create build args: %w\", err)\n\t}\n\n\tswitch {\n\tcase a.DockerArtifact != nil:\n\t\t// Required artifacts cannot be resolved when `ResolveDependencyImages` runs prior to a completed build sequence (like `skaffold build` or the first iteration of `skaffold dev`).\n\t\t// However it only affects the behavior for Dockerfiles with ONBUILD instructions, and there's no functional change even for those scenarios.\n\t\t// For single build scenarios like `build` and `run`, it is called for the cache hash calculations which are already handled in `artifactHasher`.\n\t\t// 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`)\n\t\tdeps := docker.ResolveDependencyImages(a.Dependencies, r, false)\n\n\t\targs, evalErr := docker.EvalBuildArgsWithEnv(cfg.Mode(), a.Workspace, a.DockerArtifact.DockerfilePath, a.DockerArtifact.BuildArgs, deps, envTags)\n\t\tif evalErr != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to evaluate build args: %w\", evalErr)\n\t\t}\n\t\tpaths, err = docker.GetDependencies(ctx, docker.NewBuildConfig(a.Workspace, a.ImageName, a.DockerArtifact.DockerfilePath, args), cfg)\n\n\tcase a.KanikoArtifact != nil:\n\t\tdeps := docker.ResolveDependencyImages(a.Dependencies, r, false)\n\t\targs, evalErr := docker.EvalBuildArgsWithEnv(cfg.Mode(), kaniko.GetContext(a.KanikoArtifact, a.Workspace), a.KanikoArtifact.DockerfilePath, a.KanikoArtifact.BuildArgs, deps, envTags)\n\t\tif evalErr != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to evaluate build args: %w\", evalErr)\n\t\t}\n\t\tpaths, err = docker.GetDependencies(ctx, docker.NewBuildConfig(kaniko.GetContext(a.KanikoArtifact, a.Workspace), a.ImageName, a.KanikoArtifact.DockerfilePath, args), cfg)\n\n\tcase a.BazelArtifact != nil:\n\t\tpaths, err = bazel.GetDependencies(ctx, a.Workspace, a.BazelArtifact)\n\n\tcase a.JibArtifact != nil:\n\t\tpaths, err = jib.GetDependencies(ctx, a.Workspace, a.JibArtifact)\n\n\tcase a.CustomArtifact != nil:","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/graph/dependencies.go#L116-L152","documentation":"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'.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Set the missing environment variable in the shell/CI environment or via skaffold.yaml `deploy`/`portForward` env configuration.","Provide default values for the build args in the Dockerfile (`ARG MYVAR=default`) so evaluation succeeds without the env var.","For ONBUILD-dependent args, ensure the referenced dependency artifacts are built first, or accept that the first dev loop skips them.","Run with `-vdebug` to see the exact build arg and template that failed evaluation."],"exampleFix":"// before (skaffold.yaml)\nbuildArgs: { MYVAR: '{{.UNSET_VAR}}' }\n// after (default in Dockerfile or set the var)\n// Dockerfile: ARG MYVAR=default\n// or shell: export UNSET_VAR=value","handlingStrategy":"validation","validationCode":"// Ensure every ${VAR} referenced in build args exists before calling Skaffold APIs\nfor _, v := range buildArgs {\n\tfor _, m := range envVarPattern.FindAllStringSubmatch(v, -1) {\n\t\tif os.Getenv(m[1]) == \"\" {\n\t\t\treturn fmt.Errorf(\"env var %s used in build args is unset\", m[1])\n\t\t}\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Provide Dockerfile ARG defaults so evaluation never depends on ambient env","Export required env vars in CI before invoking Skaffold","Validate Go-template syntax in skaffold.yaml build args","Expect first dev-loop evaluation gaps for ONBUILD-dependent args"],"tags":["docker","build-args","templates"],"backgroundTag":"build-args-evaluation-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}