So thanks to the answer by @Barmar, and comments by @TobySpeight along with their answer not working on our Gitlab CI pipeline job, running in a docker
image, we have to install zsh
and create the following script fileā¦
#!/usr/bin/env zsh
set -o pipefail;
counter=0;
while ! { output=$(docker compose --project-directory ./app --env-file ./.env exec php vendor/bin/pest --coverage-clover=clover.xml | tee /dev/fd/3) } 3>&1; do
counter=$((counter+1));
if [[ $output != *"done"* ]]; then
echo "Attempt $counter failed. Aborting.";
exit 1;
fi
echo "Attempt $counter failed, but with known issue.";
if [[ $counter -ge 5 ]]; then
echo "Too many attempts. Aborting.";
exit 1;
fi;
echo "Re-trying...";
done;
For some reason, using sh
or bash
gave an "Unexpected token do" syntax error.