From 061596d80279701af4bb5dad76329d7dfc6f6af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Sat, 2 Jul 2022 15:56:08 +0200 Subject: [PATCH] Gracefully handle non-zero exit code in local backend (#1002) A non-zero exit code signifies a pipeline failure, but is not a fatal error in the agent. Since exec reports this as exec.ExitError, this has to be handled explicitly. This also fixes logs not being shown on build errors. --- pipeline/backend/local/local.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pipeline/backend/local/local.go b/pipeline/backend/local/local.go index 5cb8bb77c..3afc8c0d9 100644 --- a/pipeline/backend/local/local.go +++ b/pipeline/backend/local/local.go @@ -94,9 +94,17 @@ func (e *local) Exec(ctx context.Context, proc *types.Step) error { // Wait for the pipeline step to complete and returns // the completion results. func (e *local) Wait(context.Context, *types.Step) (*types.State, error) { + err := e.cmd.Wait() + ExitCode := 0 + if eerr, ok := err.(*exec.ExitError); ok { + ExitCode = eerr.ExitCode() + // Non-zero exit code is a build failure, but not an agent error. + err = nil + } return &types.State{ - Exited: true, - }, e.cmd.Wait() + Exited: true, + ExitCode: ExitCode, + }, err } // Tail the pipeline step logs.