Fix silent get_sources failure caused by SIGPIPE in git version check
What does this MR do?
Replaces head -n1 with sed -n '1p' in IfGitVersionIsAtLeast (shells/bash.go) to prevent SIGPIPE from silently aborting the get_sources script.
The IfGitVersionIsAtLeast function uses a sort ... | head -n1 pipeline to compare git versions. head -n1 closes the pipe after reading the first line, so sort receives SIGPIPE (exit code 141) when writing the second line. Under set -o pipefail + set -o errexit (enabled in the generated script), this SIGPIPE silently aborts the entire get_sources script:
- The clone/fetch commands after the version check never execute.
- The project directory is never created.
- The next stage fails with
No such file or directory. - The job fails with
exit code 1and no error output indicating the root cause.
This is intermittent (depends on kernel scheduling timing), so retries usually succeed. It is triggered when FF_USE_GIT_NATIVE_CLONE=true + GIT_STRATEGY=clone.
Replacing head -n1 with sed -n '1p' fixes this: sed reads all input without closing the pipe early, so sort never receives SIGPIPE and the exit code is 0. Single-line change.
Why was this MR needed?
CI jobs intermittently fail silently in the get_sources stage with exit code 1 and no error output, only when FF_USE_GIT_NATIVE_CLONE=true + GIT_STRATEGY=clone. The root cause is a SIGPIPE in the git version-check pipeline that, combined with pipefail + errexit + the : | eval wrapper, aborts the script without any error message. See #39680 (closed) for full root-cause analysis, reproduction steps, and evidence.
The head -n1 pipeline in IfGitVersionIsAtLeast has never been modified — the current main branch (shells/bash.go:304) still contains it, so all gitlab-runner versions are affected.
What's the best way to test this MR?
Unit test: Test_BashWriter_IfGitVersionIsAtLeast in shells/bash_test.go verifies the generated script uses sed -n '1p' instead of head -n1.
go test ./shells/ -run Test_BashWriter_IfGitVersionIsAtLeast -vReproduction: see the "Steps to reproduce" section in #39680 (closed). A minimal shell script reproduces the SIGPIPE trigger and verifies the fix:
- Original (
head -n1): 49 out of 50 iterations failed (exit code normalized to 1). - Fixed (
sed -n '1p'): all 50 iterations succeeded.
What are the relevant issue numbers?
Closes #39680 (closed)