【问题标题】:How do I make xunit stop the jenkins pipeline on fail?如何让 xunit 在失败时停止詹金斯管道?
【发布时间】:2018-01-25 04:29:19
【问题描述】:

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 服务是否有执行此操作的参数?

【问题讨论】:

  • 一般来说,如果你想构建失败,你必须抛出一个退出状态!= 0
  • 我可以使用哪些错误级别?只是失败、成功和不稳定?

标签: jenkins jenkins-plugins jenkins-pipeline xunit


【解决方案1】:

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

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

【讨论】:

  • 这对我来说更有意义。 xunit 正在正确设置构建状态,并且进程正在退出且没有错误,因此它“成功”然后由我来读取构建状态并决定我是否希望管道失败。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-12
  • 1970-01-01
  • 2019-12-02
  • 1970-01-01
  • 2022-11-11
  • 1970-01-01
  • 2020-07-20
相关资源
最近更新 更多