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

How do I make xunit stop the jenkins pipeline on fail?

.

这是我正在做的事情:

    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。检查您似乎在 windows 中的 ERRORLEVEL,如果它不为零,则通过强制“出口 1”

从管道中退出]

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