The source project of this merge request has been removed.
fix(shells): check if pipefail is supported with for loop because grep might not be installed
What does this MR do?
Changes grep for a for loop in the shell script generation in bash.go. It iterates by the words outputted by set -o to check if pipefail is a supported shell option.
Why was this MR needed?
grep is not always installed in custom CI images but the runner uses it when starting the shell session. The shell errors are shown when grep is not installed, confusing CI users if there is an issue in the CI job image or the script section.
/bin/bash: line 4: grep: command not foundsh: line 4: grep: command not found
What's the best way to test this MR?
It can be tested with the following .gitlab-ci.yml
test-grep-not-used-in-bash:
image: nixery.dev/shell # image with bash but not grep
script:
- 'echo "Check in the log lines above there is no error like: /bin/bash: line 4: grep: command not found"'
# pipefail should be "on" in bash options
- set -o
# "false | true" should output 1 if pipefail is enabled
- false | true; if [ $? -eq 0 ]; then echo "pipefail is disabled or not supported"; exit 1; else echo "pipefail is enabled"; fi
test-grep-not-used-in-sh:
image:
name: nixery.dev/shell
entrypoint: ["/bin/sh", "-c"] # image with sh but not grep
script:
- 'echo "Check in the log lines above there is no error like: sh: line 4: grep: command not found"'
# pipefail should be "on" in sh options
- set -o
# "false | true" should output 1 if pipefail is enabled
- false | true; if [ $? -eq 0 ]; then echo "pipefail is disabled or not supported"; exit 1; else echo "pipefail is enabled"; fi