tir38
tir38

Reputation: 10421

Gradle task fails, but Travis build still passes

I'm running a build script as part of my Travis build process:

sudo: false
env:
  global:
language: android
jdk:
- oraclejdk8
android:
  components:
    ...
before_install:
    ...
script:
- ./scripts/build.sh

I'm running some Gradle tasks as part of build.sh script:

...
./gradlew clean assembleDebug testDebug -PdisablePreDex
...

testDebug is failing because of non passing test:

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.

The problem is that the Travis build is still succeeding. I thought that any failing Gradle task would fail a Travis build. I guess this isn't the case. How can I ensure that any failing Gradle task fails a Travis build?

[UPDATE]

If I move the gradle command directly into the travis.yml file then everything works like it should.

sudo: false
env:
  global:
language: android
jdk:
- oraclejdk8
android:
  components:
    ...     
before_install:
    ...
script: ./gradlew clean assembleDebug testDebug -PdisablePreDex

Upvotes: 2

Views: 709

Answers (1)

tir38
tir38

Reputation: 10421

The problem was that I wasn't passing the exit code from the Gradle line out of my script and back to Travis.

Once I checked shell script exit code and passed back to Travis everything was fine:

...
./gradlew clean assembleDebug testDebug -PdisablePreDex
if [ $? != 0 ]
then
 exit $?
fi

... # continue doing other stuff

Upvotes: 5

Related Questions