Grep always fails with CI/CD pipeline

I wanted to check our build if they contain SNAPSHOTS before building depending on environment. The following code works fine locally on my machine but it always fails in gitlab pipeline without any error, only exit code 123. To do this, I am first trying to find any place where SNAPSHOT is in my pom.xml files.

 -  snapshots=$(grep -nrH --include="pom.xml" "SNAPSHOT" )

Why is the code above failing with exit 123 in gitlab but works perfectly fine running locally on my machine?

No one who knows?