I have gitlab pipeline, where at the end of execution, there is a text file generated. In that, I am trying to search for strings with Error and want to show the job as failed in the pipeline.
So. I added below part of code at the end.
.check_remote_log: &check_remote_log
- ls -la
- returnCode=$(grep -c "Error:" outfile)
- echo "Return code received $returnCode"
- if [ $returnCode -ge 1 ]; then exit 1; fi
And calling this at the end of steps as
- echo "Now checking log file for returnCode"
- *check_remote_log
What I observed in the output is, the file is getting generated as I can see in the ls command. But it is failing at the grep step.
But these commands are working when I ran individually on a linux machine. Please suggest.
Even I tried below command but giving a different error.
if [[ $(grep "Error" outfile) ]] ; then exit 1; else echo "No errors in outfile"; fi
sh: 0/1: unknown operand
When there is error also in the output, getting as below.