How do I make Jenkins build fail when Maven unit tests fail?

后端 未结 3 2052
粉色の甜心
粉色の甜心 2020-12-08 13:06

I\'m using Jenkins, Maven 3.1, and Java 1.6. I have the following Maven job set up in Jenkins with the following goals and options ...

clean install -U -P c         


        
相关标签:
3条回答
  • 2020-12-08 13:40

    Another hack that can be useful is to use groovy post-build to check and set test result.

    e.g. this groovy gets build result, appends useful things to build description and sets build result to UNSTABLE in the case that there are no pass or fail but all tests skipped.

    def currentBuild = Thread.currentThread().executable
    // must be run groovy post-build action AFTER harvest junit xml  if you use junit xml test results
    testResult1 = currentBuild.testResultAction
    
    currentBuild.setDescription(currentBuild.getDescription() + "\n pass:"+testResult1.result.passCount.toString()+", fail:"+testResult1.result.failCount.toString()+", skip:"+testResult1.result.skipCount.toString())
    
    // if no pass, no fail all skip then set result to unstable
    if (testResult1.result.passCount == 0 && testResult1.result.failCount == 0 && testResult1.result.skipCount > 0) {
       currentBuild.result = hudson.model.Result.UNSTABLE
    }
    
    currentBuild.setDescription(currentBuild.getDescription() + "\n" + currentBuild.result.toString())
    
    def ws = manager.build.workspace.getRemote()
    myFile = new File(ws + "/VERSION.txt")
    desc = myFile.readLines()
    currentBuild.setDescription(currentBuild.getDescription() + "\n" + desc)
    
    0 讨论(0)
  • 2020-12-08 13:43

    Use Text Finder plugin. Configure it to look for There are test failures and downgrade the build to FAILED

    0 讨论(0)
  • 2020-12-08 13:51

    You can add -Dmaven.test.failure.ignore=false to the MAVEN_OPTS if you click on Advanced button in the Build section of your Jenkins Job.

    See Maven Surefire Plugin - surefire:test options for reference.

    0 讨论(0)
提交回复
热议问题