{"record":{"id":"95bb5c336e4d1883","repo":"GoogleContainerTools/skaffold","slug":"environment-variables-missing-for-template-keys","errorCode":null,"errorMessage":"environment variables missing for template keys","messagePattern":"environment variables missing for template keys","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/tag/env_template.go","lineNumber":61,"sourceCode":"\t}, nil\n}\n\n// GenerateTag generates a tag from a template referencing environment variables.\nfunc (t *envTemplateTagger) GenerateTag(ctx context.Context, image latest.Artifact) (string, error) {\n\t// The method with missingkey=invalid option does not fail if the referenced variable does not exist in the map.\n\t// It will be replaced by <no value> if no other Go template method handles the missing key.\n\t// This gives us an opportunity to handle missing keys with other Go template methods. For example, the default method\n\t// can be used to set a default value for a missing key. The evaluation of {{default \"bar\" .FOO}} should be \"bar\" and\n\t// tagging should succeed if the environment variable .FOO does not exist.\n\ttag, err := util.ExecuteEnvTemplate(t.Template.Option(\"missingkey=invalid\"), map[string]string{\n\t\t\"IMAGE_NAME\": image.ImageName,\n\t})\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\t// return error due to missing keys\n\tif strings.Contains(tag, \"<no value>\") {\n\t\treturn \"\", fmt.Errorf(\"environment variables missing for template keys\")\n\t}\n\n\treturn tag, nil\n}\n","sourceCodeStart":43,"sourceCodeEnd":66,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/tag/env_template.go#L43-L66","documentation":"The env template Tagger executes the configured template with the process environment as its data. When an environment variable referenced by a template key is not set, text/template renders the literal '<no value>'; this Tagger detects that and returns 'environment variables missing for template keys' rather than producing a broken image tag.","triggerScenarios":"GenerateTag is called with a template like '{{.RELEASE}}' but the referenced env var (RELEASE) is unset or empty in the shell/CI environment running skaffold build.","commonSituations":"CI pipelines where the env var is defined in one job but not passed to the build step; vars set in ~/.bashrc but not in non-interactive shells or Docker exec environments; renamed env vars after a config refactor.","solutions":["Export the missing environment variable before running skaffold (e.g. `export TAG=v1.2.3` or `TAG=v1.2.3 skaffold build`)","Ensure your CI passes the variable into the build step (env: / withEnv / --env flags)","Use `skaffold build --default-repo=...` style defaults or a different tagger (gitCommit, dateTime) that doesn't depend on env vars","Provide a template default, e.g. `{{default \"dev\" .TAG}}` via custom template funcs if available"],"exampleFix":"// before\nskaffold build  # template {{.RELEASE}}, RELEASE unset\n// after\nRELEASE=v1.2.3 skaffold build","handlingStrategy":"validation","validationCode":"// before invoking skaffold, check every var your template uses\nfor _, k := range []string{\"RELEASE\", \"TAG\"} {\n    if os.Getenv(k) == \"\" {\n        return fmt.Errorf(\"required env var %s for tag template is unset\", k)\n    }\n}","typeGuard":null,"tryCatchPattern":"tag, err := tag.GenerateFullyQualifiedImageName(ctx, tagger, image)\nif strings.Contains(err.Error(), \"environment variables missing\") {\n    return fmt.Errorf(\"export the env vars referenced by the tag template: %w\", err)\n}","preventionTips":["Export template env vars in CI before the build step","Add a pre-build smoke test that echoes each template var","Prefer gitCommit/dateTime taggers when env vars are unreliable","Document required env vars next to skaffold.yaml"],"tags":["go","skaffold","env","template","tagging"],"backgroundTag":"missing-env-var","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"}