Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions agent/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,25 @@ func (r *Runner) createTracer(ctxMeta context.Context, uploads *sync.WaitGroup,
defer uploads.Done()

stepLogger := logger.With().
Str("image", state.Pipeline.Step.Image).
Str("image", state.CurrStep.Image).
Str("workflow_id", workflow.ID).
Err(state.Process.Error).
Int("exit_code", state.Process.ExitCode).
Bool("exited", state.Process.Exited).
Err(state.CurrStepState.Error).
Int("exit_code", state.CurrStepState.ExitCode).
Bool("exited", state.CurrStepState.Exited).
Logger()

stepState := rpc.StepState{
StepUUID: state.Pipeline.Step.UUID,
Exited: state.Process.Exited,
ExitCode: state.Process.ExitCode,
Started: state.Process.Started,
Canceled: errors.Is(state.Process.Error, pipeline_errors.ErrCancel),
StepUUID: state.CurrStep.UUID,
Exited: state.CurrStepState.Exited,
ExitCode: state.CurrStepState.ExitCode,
Started: state.CurrStepState.Started,
Canceled: errors.Is(state.CurrStepState.Error, pipeline_errors.ErrCancel),
Skipped: state.CurrStepState.Skipped,
}
if state.Process.Error != nil {
stepState.Error = state.Process.Error.Error()
if state.CurrStepState.Error != nil {
stepState.Error = state.CurrStepState.Error.Error()
}
if state.Process.Exited {
if state.CurrStepState.Exited {
stepState.Finished = time.Now().Unix()
}

Expand All @@ -68,21 +69,21 @@ func (r *Runner) createTracer(ctxMeta context.Context, uploads *sync.WaitGroup,

stepLogger.Debug().Msg("update step status complete")
}()
if state.Process.Exited {
if state.CurrStepState.Exited {
return nil
}
if state.Pipeline.Step.Environment == nil {
state.Pipeline.Step.Environment = map[string]string{}
if state.CurrStep.Environment == nil {
state.CurrStep.Environment = map[string]string{}
}

// TODO: find better way to update this state and move it to pipeline to have the same env in cli-exec
state.Pipeline.Step.Environment["CI_MACHINE"] = r.hostname
state.CurrStep.Environment["CI_MACHINE"] = r.hostname

state.Pipeline.Step.Environment["CI_PIPELINE_STARTED"] = strconv.FormatInt(state.Pipeline.Started, 10)
state.CurrStep.Environment["CI_PIPELINE_STARTED"] = strconv.FormatInt(state.Workflow.Started, 10)

state.Pipeline.Step.Environment["CI_STEP_STARTED"] = strconv.FormatInt(state.Pipeline.Started, 10)
state.CurrStep.Environment["CI_STEP_STARTED"] = strconv.FormatInt(state.Workflow.Started, 10)

state.Pipeline.Step.Environment["CI_SYSTEM_PLATFORM"] = runtime.GOOS + "/" + runtime.GOARCH
state.CurrStep.Environment["CI_SYSTEM_PLATFORM"] = runtime.GOOS + "/" + runtime.GOARCH

return nil
}
Expand Down
2 changes: 2 additions & 0 deletions pipeline/backend/types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type State struct {
ExitCode int `json:"exit_code"`
// Container exited, true or false
Exited bool `json:"exited"`
// Step was skipped by the runtime (OnSuccess/OnFailure filter)
Skipped bool `json:"skipped"`
// Container is oom killed, true or false
// TODO (6024): well known errors as string enum into ./errors.go
OOMKilled bool `json:"oom_killed"`
Expand Down
28 changes: 14 additions & 14 deletions pipeline/runtime/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func (r *Runtime) Run(runnerCtx context.Context) error {
var stepErr *pipeline_errors.ErrInvalidWorkflowSetup
if errors.As(err, &stepErr) {
state := new(state.State)
state.Pipeline.Step = stepErr.Step
state.Pipeline.Error = stepErr.Err
state.Process = backend.State{
state.CurrStep = stepErr.Step
state.Workflow.Error = stepErr.Err
state.CurrStepState = backend.State{
Error: stepErr.Err,
Exited: true,
ExitCode: 1,
Expand Down Expand Up @@ -103,19 +103,19 @@ func (r *Runtime) traceStep(processState *backend.State, err error, step *backen
}

state := new(state.State)
state.Pipeline.Started = r.started
state.Pipeline.Step = step
state.Pipeline.Error = r.err.Get()
state.Workflow.Started = r.started
state.CurrStep = step
state.Workflow.Error = r.err.Get()

// We have an error while starting the step
if processState == nil && err != nil {
state.Process = backend.State{
state.CurrStepState = backend.State{
Error: err,
Exited: true,
OOMKilled: false,
}
} else if processState != nil {
state.Process = *processState
state.CurrStepState = *processState
}

if traceErr := r.tracer.Trace(state); traceErr != nil {
Expand All @@ -141,18 +141,18 @@ func (r *Runtime) execAll(runnerCtx context.Context, steps []*backend.Step) <-ch
Str("step", step.Name).
Msg("prepare")

switch rErr := r.err.Get(); {
case rErr != nil && !step.OnFailure:
rErr := r.err.Get()
if rErr != nil && !step.OnFailure {
logger.Debug().
Str("step", step.Name).
Err(rErr).
Msgf("skipped due to OnFailure=%t", step.OnFailure)
return nil
case rErr == nil && !step.OnSuccess:
return r.traceStep(&backend.State{Skipped: true}, nil, step)
}
if rErr == nil && !step.OnSuccess {
logger.Debug().
Str("step", step.Name).
Msgf("skipped due to OnSuccess=%t", step.OnSuccess)
return nil
return r.traceStep(&backend.State{Skipped: true}, nil, step)
}

// Trace started.
Expand Down
Loading