cirruslabs / cirrus-ci-agent

Agent to execute Cirrus CI tasks
Mozilla Public License 2.0
13 stars 6 forks source link

Better pipeline failure detection #332

Closed edigaryev closed 11 months ago

edigaryev commented 11 months ago

I've created the following script instruction to run on FreeBSD:

install_golang_script:
  - wget --no-verbose -O - https://go.dev/dl/go1.21.5.freebsd-amd64.tar.gz | tar -C /usr/local -xz

And it was marked as succeed, but in reality, it failed because wget was not installed:

Screenshot 2023-12-18 at 17 18 56

This seems to be happening because the pipefail option is only set on when using Bash:

https://github.com/cirruslabs/cirrus-ci-agent/blob/445a87400c7f080f7bc7a142b76284d47ae61afe/internal/executor/cmd.go#L44-L46

It seems that we can try to enable the pipefail option opportunistically by utilizing the || (logical OR expression) to avoid failing the whole script if the option is not defined for a given shell.

Also, nowadays most shells seems to support pipefail, for example, on OpenBSD, the /bin/sh is actually /bin/ksh:

This version of sh is actually ksh in disguise. As such, it also supports the features described in ksh(1).

...and ksh(1) supports pipefail.

On FreeBSD, /bin/sh supports pipefail option natively.

ZSH seems to support pipefail too, at least on macOS:

% zsh -c 'set -o pipefail' ; echo $?
0