2017-08-16 47 views
1

This guy seems to have the same problem如何让xunit停止jenkins管道失败?

下面是我在做什么:

stage('Test') { 
     steps { 
      bat "\"${tool 'VSTestRunner'}\" %WORKSPACE%\\MyApp\\bin\\Debug\\MyApp.dll /logger:trx & exit 0" 
      // The test publish is responsible for decided whether the test stage failed 
      step([$class : 'XUnitPublisher', 
       testTimeMargin: '3000', 
       thresholdMode: 1, 
       thresholds: [ 
        [$class: 'FailedThreshold', failureNewThreshold: '', failureThreshold: '1', unstableNewThreshold: '', unstableThreshold: ''], 
        [$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: ''] 
       ], 
       tools : [[$class: 'MSTestJunitHudsonTestType', 
        deleteOutputFiles: true, 
        failIfNotNew: false, 
        pattern: "TestResults\\*.trx", 
        skipNoTestFiles: false, 
        stopProcessingIfError: true 
       ]] 
      ]) 

     } 
    } 

如果测试失败管道仍在继续。

我希望能够通过xunit设置来控制管道是否继续。有没有比这更优雅的方式:

if (currentBuild.result.equals("FAILURE")) { 
    throw "Test results did not pass thresholds" 
} 

此外,“stopProcessingIfError”是做什么的?我认为如果超过了错误阈值,它会停止管道,但事实并非如此。 xunit服务有没有这样做的参数?

+0

通常,如果你想失败一个构建,你必须抛出退出状态!= 0 – OK999

+0

我有什么错误级别可用于我?只是失败,成功和不稳定? – red888

回答

1

FAILED,SUCCESS和UNSTABLE是jenkins的状态,而不是退出状态。退出状态应该来自正在执行的进程。因此,如果测试失败,您的解决方案是设置exit 1(或非零)。您的批处理步骤似乎设置了出口0.请检查ERRORLEVEL,因为您似乎在窗口中,并且如果其非零,则通过强制退出1从管道中突然跳出注:它可以(我指的是退出代码中的1)

+0

这对我来说更有意义。 xunit正确地设置了构建状态,并且该进程没有错误地退出,所以它“成功”,然后在那一刻它就由我来读取构建状态并决定我是否希望管道失败。 – red888

相关问题