代码之家  ›  专栏  ›  技术社区  ›  kutschkem

失败的詹金斯建立后检查样式报告

  •  1
  • kutschkem  · 技术社区  · 7 年前

    我想减少Jenkins从服务器上的负载,并在出现checkstyle/findbugs问题时为开发人员提供更快的反馈。当前生成正在运行,但如果存在支票样式问题,则仍标记为失败。

    stage ('Reports') {
        step([$class: 'FindBugsPublisher', canComputeNew: false, canRunOnFailed: true, defaultEncoding: '', excludePattern: '', failedTotalHigh: '0', failedTotalNormal: '200', failedTotalLow: '350', healthy: '', includePattern: '', pattern: '**/spotbugsXml.xml', unHealthy: ''])
        step([$class: 'CheckStylePublisher', canComputeNew: false, canRunOnFailed: true, defaultEncoding: '', healthy: '', pattern: '**/maven_checks.xml ',failedTotalHigh: '0', failedTotalNormal: '0',failedTotalLow: '0', unHealthy: ''])
        step([$class: 'WarningsPublisher', canComputeNew: false, canResolveRelativePaths: false, consoleParsers: [[parserName: 'Maven'], [parserName: 'userdef-protobuf'], [parserName: 'userdef-xtend']], defaultEncoding: '', excludePattern: '', healthy: '', includePattern: '', messagesPattern: '', unHealthy: ''])
    } 
    

    如果出现问题,我希望此阶段立即使构建失败,而不是等到测试结束等。当前后续阶段仍在执行。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Giel Berkers    7 年前

    我遇到了同样的问题,尽管看起来很蹩脚,但我现在做的很简单 grep 在我身上 checkstyle.xml 查看是否有错误,如果有,则生成失败:

    def foundErrors = sh(
        script: "cat test-reports/checkstyle.xml | grep 'severity=\"error\"' | wc -l",
        returnStdout: true
    )
    if (foundErrors.toInteger() > 0) {
        error("Build failed because of errors in static code analysis.")
    }
    

    我知道,这是非常跛脚,但在我的情况下,它做的工作。不确定这是否对您有帮助,因为我只需要担心一个XML文件,而您似乎不需要担心这个问题,但是,嘿,至少是这样;-)