问题
I'm using xcodebuild inside a bash script on a continuous integration server.
I would like to know when a build as failed in the script, so I can exit prematurely from it and mark the build as failed.
xcodebuild displays a BUILD FAILED message to the console, but I don't succeed in getting a return value.
How can I achieve this?
Thanks in advance
回答1:
I solved my problem using this command: xcodebuild -... || exit 1
回答2:
xcodebuild
always returns 0, regardless of the actual test result. You should check for either ** BUILD FAILED **
or ** BUILD SUCCEEDED **
in the output to know whether tests pass or not.
回答3:
You can use the "$?" variable to get the return code of the previous command.
xcodebuild -...
if [[ $? == 0 ]]; then
echo "Success"
else
echo "Failed"
fi
回答4:
Xcodebuild can return any of the error codes listed here and not restricted to EX_OK (or int 0).
However, I learnt from solution provided by Dmitry and modified as following. It works for me and I hope it could be helpful.
xcodebuild -project ......
if test $? -eq 0
then
echo "Success"
else
echo "Failed"
fi
回答5:
Maybe it's not because of the xcodebuild not returning non-zero when build failed. Your shell script continuing to run regardless of the returning-error line might be the result of that you didn't run the script with a "-e" option.
Try put #!/bin/bash -e ahead of the script file.
回答6:
Whether the compiled product (.a or .ipa file)exists
来源:https://stackoverflow.com/questions/7363459/how-to-get-the-return-value-of-xcodebuild