How to get the return value of xcodebuild?

天涯浪子 提交于 2019-11-30 03:00:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!