While running a script on CI (Gitlab, Docker container running Alpine Linux), I am getting sporadic failures with signal 141 which seems to indicate a "SIGPIPE". But I do not understand which step is failing or what to do about debugging it.
#!/usr/bin/env bash
set -euxo pipefail
set -a
# ...
git fetch --tags
RELEASE=$(git tag | grep -E "${BUILD_ENV}-release-(\d+)" | cut -d"-" -f3 | sort -nr | head -1)
RELEASE=$(( RELEASE + 1 ))
The sporadic error seems to happen inside the pipe in the second to last line, the log I get is:
++ git tag
++ cut -d- -f3
++ sort -nr
++ grep -E 'prod-release-(\d+)'
++ head -1
+ RELEASE=323
ERROR: Job failed: exit code 141
How would I go about debugging this to figure out which line actually failed? It looks like it got the RELEASE variable populated successfully but then somehow still blew up?