GoogleContainerTools/skaffold · error
environment variables missing for template keys
Error message
environment variables missing for template keys
What it means
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.
Source
Thrown at pkg/skaffold/tag/env_template.go:61
}, nil
}
// GenerateTag generates a tag from a template referencing environment variables.
func (t *envTemplateTagger) GenerateTag(ctx context.Context, image latest.Artifact) (string, error) {
// The method with missingkey=invalid option does not fail if the referenced variable does not exist in the map.
// It will be replaced by <no value> if no other Go template method handles the missing key.
// This gives us an opportunity to handle missing keys with other Go template methods. For example, the default method
// can be used to set a default value for a missing key. The evaluation of {{default "bar" .FOO}} should be "bar" and
// tagging should succeed if the environment variable .FOO does not exist.
tag, err := util.ExecuteEnvTemplate(t.Template.Option("missingkey=invalid"), map[string]string{
"IMAGE_NAME": image.ImageName,
})
if err != nil {
return "", err
}
// return error due to missing keys
if strings.Contains(tag, "<no value>") {
return "", fmt.Errorf("environment variables missing for template keys")
}
return tag, nil
}
View on GitHub (pinned to a1189de023)
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
Example fix
// before
skaffold build # template {{.RELEASE}}, RELEASE unset
// after
RELEASE=v1.2.3 skaffold build Defensive patterns
Strategy: validation
Validate before calling
// before invoking skaffold, check every var your template uses
for _, k := range []string{"RELEASE", "TAG"} {
if os.Getenv(k) == "" {
return fmt.Errorf("required env var %s for tag template is unset", k)
}
} Try / catch
tag, err := tag.GenerateFullyQualifiedImageName(ctx, tagger, image)
if strings.Contains(err.Error(), "environment variables missing") {
return fmt.Errorf("export the env vars referenced by the tag template: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- parsing template: %w
- bad timezone provided: %q, error: %s
- %q is not a valid git tagger variant
- unable to find git commit: %w
- getting git status: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/95bb5c336e4d1883.
Report an issue: GitHub.