I don't think Xcode server is failing to run the script.
That error means to me that Xcode server is running the script and the last command to run in the shell is failing with exit code 252 and the shell is passing that exit code on to the Xcode server. So you need to figure out what command in the shell script is not happy when run on the Xcode Server.
Add debug logging to the shell. Almost all shell commands should be written as:
if rm -rf ${somedir:?}; then
echo "Deleting $somedir OK."
else
echo "Error deleting $somedir."
fi
Instead of just:
rm -rf ${somedir:?}
cd ..
# And so on.
Then, you can look at the shell script output in the Xcode Server Bot logs and have a better hint at what the problem is.