hashicorp/packer · error
AddArtifacts: failed to add artifact to build %q: %w
Error message
AddArtifacts: failed to add artifact to build %q: %w
What it means
Returned by Build.AddArtifacts when an artifact fails packerSDKRegistry Image.Validate. Validation requires a usable image identity (non-empty ImageID and ProviderName), so artifacts lacking these cannot be attached to the build.
Source
Thrown at internal/hcp/registry/types.builds.go:89
// TODO: (nywilken) Determine why we skip labels already set
// if _, ok := build.Labels[k]; ok {
// continue
// }
build.Labels[k] = v
}
}
// AddArtifacts appends one or more artifacts to the build.
func (build *Build) AddArtifacts(artifacts ...packerSDKRegistry.Image) error {
if build.Artifacts == nil {
build.Artifacts = make(map[string]packerSDKRegistry.Image)
}
for _, artifact := range artifacts {
if err := artifact.Validate(); err != nil {
return fmt.Errorf("AddArtifacts: failed to add artifact to build %q: %w", build.ComponentType, err)
}
if build.Platform == "" {
build.Platform = artifact.ProviderName
}
build.MergeLabels(artifact.Labels)
build.Artifacts[artifact.String()] = artifact
}
return nil
}
// IsNotDone returns true if build does not satisfy all requirements of a completed build.
// A completed build must have a valid ID, one or more Artifacts, and its Status is HashicorpCloudPacker20230101BuildStatusBUILDDONE.
func (build *Build) IsNotDone() bool {
hasBuildID := build.ID != ""
hasNoArtifacts := len(build.Artifacts) == 0View on GitHub (pinned to eb36e3c3e4)
Solutions
- Ensure the builder produces an artifact with a valid external identifier (e.g. an AMI ID, image name)
- Verify ImageID and ProviderName are set when constructing packerSDKRegistry.Image values in custom plugins
- Inspect the wrapped Validate error (%w) for the exact missing field
- Skip registering non-image artifacts rather than forcing them into the HCP registry
Example fix
// before
build.AddArtifacts(packerSDKRegistry.Image{ImageID: "", ProviderName: "aws"})
// after
if artifact.ExternalIdentifier == "" {
return fmt.Errorf("artifact has no external identifier")
}
build.AddArtifacts(packerSDKRegistry.Image{ImageID: artifact.ExternalIdentifier, ProviderName: "aws"}) Defensive patterns
Strategy: validation
Validate before calling
img := packerSDKRegistry.Image{ImageID: artifact.ExternalIdentifier, ProviderName: provider, ProviderRegion: region}
if err := img.Validate(); err != nil {
return fmt.Errorf("skip invalid artifact: %w", err)
}
build.AddArtifacts(img) Type guard
func validImage(img packerSDKRegistry.Image) bool {
return img.ImageID != "" && img.ProviderName != ""
} Prevention
- Always set ImageID and ProviderName when constructing registry Images
- Filter placeholder/empty artifacts before attaching to builds
- Test custom builders against Image.Validate in unit tests
When it happens
Trigger: Any AddArtifacts call where an Image has an empty ImageID (artifact.ExternalIdentifier) or ProviderName; also reached indirectly via NewBuildFromCloudPackerBuild, AddArtifactToBuild, and doCompleteBuild artifact registration.
Common situations: Builders that emit artifacts without external identifiers (e.g. docker builder not exporting, or local files); misconfigured post-processors dropping IDs; populating builds from cloud records with blank provider fields.
Related errors
- there is no iteration associated with the channel %s
- there is no iteration associated with the channel %s
- No HCP Packer-compatible artifacts were found for the build
- failed to update HCP Packer artifacts for %q: %s
- NewBuildFromCloudPackerBuild: %w
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/e165dbd0a5b3da28.
Report an issue: GitHub.