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.
This commit is contained in:
Florian Märkl 2022-07-02 15:56:08 +02:00 committed by GitHub
parent 3f73d5bf53
commit 061596d802
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.