简体   繁体   中英

How can i set the jenkins job to pass when the test are actually failed

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

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"
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM