It is usual when running pipeline, it will expect to continue even execute failure. Previously, need to use try..catch and change currentBuild.currentResult to unstable (Originally it can set as SUCCESS, FAILURE, UNSTABLE). Since Jenkine 2.26, you can use statement unstable to identify it.
This example will run command gradle test failure to mark warning in pipeline.
script {
try {
sh """
gradle test
"""
} catch(Exception e) {
unstable "Error found in unit test. Message: "+e.getMessage()
} finally {
try {
junit "build/test-results/test/*.xml"
} catch(Exception e) {
unstable "Error found when export JUnit report to Jenkins. Message: "+e.getMessage()
}
}
}
Leave a Reply