xcodebuild always returns 0 even if the build fails. To detect errors, you can use the script as follows:
build_errors_file=build_errors.log # Pipe errors to file xcodebuild 2>$build_errors_file errors=`grep -wc "The following build commands failed" $build_errors_file` if [ "$errors" != "0" ] then echo "BUILD FAILED. Error Log:" cat $build_errors_file rm $build_errors_file exit 1 fi rm $build_errors_file # ... continue
I confirmed that ** BUILD FAILED ** will not be printed when xcodebuild starts with the archive parameter, so it seems that the line to look for is "The following build commands failed."
source share