From 6494030bc3ee3067bb97fdfd44be24167cf2c766 Mon Sep 17 00:00:00 2001 From: Tim Huynh Date: Fri, 27 Oct 2023 11:03:11 -0500 Subject: [PATCH] fix(step): set step error for on_start failure using bad image (#527) * working code * fix step in local * add comment --------- Co-authored-by: TimHuynh --- executor/linux/step.go | 4 ++++ executor/local/step.go | 4 ++++ internal/step/snapshot.go | 6 ++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/executor/linux/step.go b/executor/linux/step.go index afebcbf8..34b016a7 100644 --- a/executor/linux/step.go +++ b/executor/linux/step.go @@ -152,6 +152,10 @@ func (c *client) ExecStep(ctx context.Context, ctn *pipeline.Container) error { // run the runtime container err = c.Runtime.RunContainer(ctx, ctn, c.pipeline) if err != nil { + // set step status to error and step error + _step.SetStatus(constants.StatusError) + _step.SetError(err.Error()) + return err } diff --git a/executor/local/step.go b/executor/local/step.go index dc34bb12..36f7e726 100644 --- a/executor/local/step.go +++ b/executor/local/step.go @@ -83,6 +83,10 @@ func (c *client) ExecStep(ctx context.Context, ctn *pipeline.Container) error { // run the runtime container err = c.Runtime.RunContainer(ctx, ctn, c.pipeline) if err != nil { + // set step status to error and step error + _step.SetStatus(constants.StatusError) + _step.SetError(err.Error()) + return err } diff --git a/internal/step/snapshot.go b/internal/step/snapshot.go index 88ece98c..1efb19cb 100644 --- a/internal/step/snapshot.go +++ b/internal/step/snapshot.go @@ -16,8 +16,10 @@ import ( // Snapshot creates a moment in time record of the // step and attempts to upload it to the server. func Snapshot(ctn *pipeline.Container, b *library.Build, c *vela.Client, l *logrus.Entry, r *library.Repo, s *library.Step) { - // check if the build is not in a canceled status - if !strings.EqualFold(s.GetStatus(), constants.StatusCanceled) { + // check if the build is not in a canceled status or error status + logrus.Debugf("Snapshot s: %s %s", s.GetName(), s.GetStatus()) + if !strings.EqualFold(s.GetStatus(), constants.StatusCanceled) && + !strings.EqualFold(s.GetStatus(), constants.StatusError) { // check if the container is running in headless mode if !ctn.Detach { // update the step fields to indicate a success