Skip to content

Commit

Permalink
fix(step): set step error for on_start failure using bad image (#527)
Browse files Browse the repository at this point in the history
* working code

* fix step in local

* add comment

---------

Co-authored-by: TimHuynh <[email protected]>
  • Loading branch information
timhuynh94 and TimHuynh authored Oct 27, 2023
1 parent bcdf8e4 commit 6494030
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions executor/linux/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions executor/local/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 4 additions & 2 deletions internal/step/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6494030

Please sign in to comment.