Reputation: 599
I have a Gradle build in Jenkins with various JUnit tests that are executed as part of the build. Now when some of the tests fail the complete build is marked as failed - because Gradle says the build failed.
How can I convince Gradle to succeed the build and then Jenkins to mark the build as unstable? With ant this was no problem at all.
Upvotes: 25
Views: 14097
Reputation: 1
Since just ignoring the failed test could not be used in my case i found out the following. If you are using a scripted jenkinsfile. It is possible to wrap your test stage in a try-catch statement.
try {
stage('test') {
sh './gradlew test'
}
} catch (e) {
echo "Test FAILED"
}
This will catch the build exception thrown by gradle but it marks the build as unstable.
Upvotes: 0
Reputation: 6971
Use the ignoreFailures property in the test task.
apply plugin: 'java'
test {
ignoreFailures = true
}
Upvotes: 25
Reputation: 1043
You can use external properties to solve this problem.
if (!ext.has('ignoreTestFailures')) {
ext.ignoreTestFailures = false
}
test {
ignoreFailures = project.ext.ignoreTestFailures
}
In this setup by default failures will fail the build. But if you call Gradle like so: gradle -PignoreTestFailures=true test
then the test failures will not fail the build. So you can configure Jenkins to ignore test failures, but to fail the build when a developer runs the tests manually.
Upvotes: 4
Reputation: 185
You can include this in your main build.gradle to be applied to all projects and all test tasks.
allprojects{
tasks.withType(Test) {
ignoreFailures=true;
}
}
Upvotes: 2