jenkins - 如何让 xunit 在失败时停止 Jenkins 管道?

标签 jenkins jenkins-plugins jenkins-pipeline xunit

This guy seems to have the same problem .

这就是我正在做的事情:

    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 服务是否有一个参数可以做到这一点?

最佳答案

FAILED、SUCCESS 和 UNSTABLE 是 jenkins 构建状态而不是退出状态。退出状态应该来自正在执行的进程。因此,如果测试失败,您的解决方案是设置 exit 1 (或非零值)。您的批处理步骤似乎正在设置退出 0。检查 ERRORLEVEL,就像您在 Windows 中一样,如果它非零,则通过强制“退出 1”从管道中退出

注意:它可以是任何值,但不应该是 0。(我指的是退出代码中的 1)

关于jenkins - 如何让 xunit 在失败时停止 Jenkins 管道?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45723559/

相关文章:

java - Jenkins CLI 连接被拒绝

jenkins - 在 jenkins 管道脚本中获取 gradle 变量

jenkins - 在 Jenkins 声明性管道的参数中定义凭证参数?

Jenkins EC2 插件在构建作业时立即启动和停止实例

docker - 使用 Docker、Google 注册表和 Google Auth 插件构建 Jenkins 管道

jenkins - 如何获取 git 最新提交消息并阻止 jenkins 构建(如果提交消息包含 [ci Skip])?

angularjs - Jenkins 的多个终端窗口?

asp.net-mvc-4 - 如何在我的解决方案配置中启用复选框 'deploy'

linux - 使用 teSTLink 时 jenkins 中的 XMLRPC 错误

jenkins - "java.io.NotSerializableException: java.io.PrintWriter"写入文件时 - Jenkins 工作流程