我正在运行构建脚本作为Travis构建过程的一部分:
sudo: false
env:
global:
language: android
jdk:
- oraclejdk8
android:
components:
...
before_install:
...
script:
- ./scripts/build.sh
我在build.sh脚本中运行了一些Gradle任务:
...
./gradlew clean assembleDebug testDebug -PdisablePreDex
...
testDebug由于未通过测试而失败:
2 tests completed, 1 failed
:MyApp:testDebugUnitTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':MyApp:testDebugUnitTest'.
> There were failing tests. See the report at: file:///home/travis/build.../build/reports/tests/debug/index.html
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
问题在于Travis构建仍然成功。我认为任何失败的Gradle任务都会导致Travis构建失败。我想这并非如此。如何确保任何失败的Gradle任务未通过Travis构建?
[UPDATE]
如果我将gradle命令直接移动到travis.yml文件中,那么一切都会像它应该的那样工作。
sudo: false
env:
global:
language: android
jdk:
- oraclejdk8
android:
components:
...
before_install:
...
script: ./gradlew clean assembleDebug testDebug -PdisablePreDex
答案 0 :(得分:4)
问题在于我没有将Gradle行的退出代码从我的脚本中传回Travis。
一旦我检查了shell脚本退出代码并传回Travis,一切都很好:
...
./gradlew clean assembleDebug testDebug -PdisablePreDex
if [ $? != 0 ]
then
exit $?
fi
... # continue doing other stuff