Reputation: 361
I'm trying to do something similar to what this guy is doing: Jenkins failed build: I Want it to pass
create a pipeline job in Jenkins for all the Known bugs tests, I want the job to PASS when all the tests are FAILED. while when even 1 test is PASS, the job will be GREEN.
I found here this solution
stage('Tests') {
steps {
script{
//running the tests
status = sh "${mvnHome}/bin/mvn clean test -e -Dgroups=categories.knownBug"
if (status === "MARK-AS-UNSTABLE") {
currentBuild.result = "STABLE"
}
}
}
}
but got an error
Unsupported operation in this context @ line 47, column 39.
if (status === "MARK-AS-UNSTABLE") {
------------EDIT--------- Thanks to @yrc I changed the code to
try {
sh "${mvnHome}/bin/mvn clean test -e -Dgroups=categories.knownBug"
} catch (err) {
echo "Caught: ${err}"
currentBuild.result = "STABLE"
}
It did help with the error msg, but I want the job to pass when one of the tests is failing. Now, both test and job has failed
Upvotes: 0
Views: 1200
Reputation: 14584
Just wrap your execution with a try-catch block.
try {
sh "${mvnHome}/bin/mvn clean test -e -Dgroups=categories.knownBug"
} catch (err) {
echo "Caught: ${err}"
currentBuild.result = "STABLE"
}
Upvotes: 1