Skip to content

Commit

Permalink
command: exit non-zero if uploading to HCP failed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lbajolet-hashicorp committed Nov 14, 2024
1 parent 8bc1fd7 commit 3f5f177
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions command/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3f5f177

Please sign in to comment.