diff --git a/internal/hcp/registry/types.bucket.go b/internal/hcp/registry/types.bucket.go index ab068a30866..b9be5fd81b1 100644 --- a/internal/hcp/registry/types.bucket.go +++ b/internal/hcp/registry/types.bucket.go @@ -642,7 +642,6 @@ func (bucket *Bucket) completeBuild( doneCh, ok := bucket.RunningBuilds[buildName] if !ok { log.Print("[ERROR] done build does not have an entry in the heartbeat table, state will be inconsistent.") - } else { log.Printf("[TRACE] signal stopping heartbeats") // Stop heartbeating @@ -662,6 +661,23 @@ func (bucket *Bucket) completeBuild( return packerSDKArtifacts, fmt.Errorf("build failed, not uploading artifacts") } + artifacts, err := bucket.doCompleteBuild(ctx, buildName, packerSDKArtifacts, buildErr) + if err != nil { + err := bucket.UpdateBuildStatus(ctx, buildName, hcpPackerModels.HashicorpCloudPacker20230101BuildStatusBUILDFAILED) + if err != nil { + log.Printf("[ERROR] failed to update build %q status to FAILED: %s", buildName, err) + } + } + + return artifacts, err +} + +func (bucket *Bucket) doCompleteBuild( + ctx context.Context, + buildName string, + packerSDKArtifacts []packerSDK.Artifact, + buildErr error, +) ([]packerSDK.Artifact, error) { for _, art := range packerSDKArtifacts { var sdkImages []packerSDKRegistry.Image decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{