From 181134a1b9fe0d20a0736a8e579c6c38faa74eed Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Wed, 13 Nov 2024 15:36:45 -0500 Subject: [PATCH] command: exit non-zero if uploading to HCP failed In the current state, a Packer build that succeeds but fails to push its metadata to HCP for reasons other than a lack of artifact will always succeed from the perspective of a user invoking `packer build`. This can be a bit misleading, as users may expect their artifacts to appear on HCP Packer if their build succeeded on Packer Core, so this commit changes this behaviour, instead reporting HCP errors as a real error if the build failed, so packer returns a non-zero error code if this happens. --- command/build.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/command/build.go b/command/build.go index 58b548b008f..3caa0b9d842 100644 --- a/command/build.go +++ b/command/build.go @@ -315,6 +315,15 @@ Check that you are using an HCP Ready integration before trying again: artifacts.Unlock() } } + + // If the build succeeded but uploading to HCP failed, + // Packer should exit non-zero, so we re-assign the + // error to account for this case. + if hcperr != nil && err == nil { + errs.Lock() + errs.m[name] = hcperr + errs.Unlock() + } }() if cla.Debug {