【问题标题】:Import cfn-lint report to Jenkins through Warnings-NG plugin通过Warnings-NG插件将cfn-lint报告导入Jenkins
【发布时间】:2021-10-11 23:28:08
【问题描述】:

我正在使用Warnings-NG plugin 成功导入 Pylint 和 YamlLint 生成的所有报告。现在我想导入cfn-lint(cloudformation yaml 文件)报告,但我遇到了问题。

我已经使用-f parseable --output-file report.out 生成了cfn-lint 报告,并使用Warnings-NG 的recordIssues tool: yamlLint(pattern: 'report.out') 将其导入到Jenkins 中,没有出现错误,但不幸的是,在导入的cloudformation 模板中没有检测到错误。

之后,我尝试将格式报告更改为 Junit 并使用可用的 Junit 工具将其导入。

// Generate the report:
cfn-lint . -f junit --output-file report-junit.out

// Import the junit report:
recordIssues tool: junitParser(pattern: 'report-junit.out')

在最后一种情况下,我遇到了 Java 错误。

有没有人尝试将cfn-lint 报告导入到 jenkins 或其他类型的应用程序中? 欢迎任何想法。 问候。

【问题讨论】:

    标签: jenkins junit yaml amazon-cloudformation


    【解决方案1】:

    我在Violations Lib 上提出了这个问题,以增加对 Cfn-Lint 报告 Junit 格式的支持,现在它已得到修复,并将在下一版本的 Warnings-NG Jenkins 插件中提供。

    如果您不想等待,我创建了一个解决方法,它基本上采用:(冒号)分隔文件(cfn-lint . -f parseable --output-file report.out)并将其修改为警告-NG RecordIssues YamlLint 期望的格式。

    我使用这个 Groovy 代码来做到这一点:

    def cfnLogFile = readFile "report.out"
    def cfnLogFileRows = cfnLogFile.readLines()
    cfnLogLine = ""
    for (row in cfnLogFileRows){
      def (c1, c2, c3, c4, c5, c6, c7) = row.tokenize(":")
      if (c6 ==~ /E.*/){
        level = "[error]"
      } else if (c6 ==~ /W.*/){
        level = "[warning]"
      } else {
        level = "[information]"
      }
      cfnLogLine = c1 + ":" + c2 + ":" + c3 + ": " + level + " " + c6 + " " + c7
    sh "echo '${cfnLogLine}' >> report_parsed.out"
    }
    

    现在,在其他步骤中,您可以上传report_parsed.out

    recordIssues(
      enabledForFailure: false,
      tool: yamlLint(pattern: '**/report_parsed.out', reportEncoding: 'UTF-8', id: 'cfn-lint', name: 'Cfn-Lint')
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-03
      • 2013-10-04
      • 1970-01-01
      • 2014-02-26
      • 1970-01-01
      • 2021-04-02
      • 2016-09-29
      • 1970-01-01
      相关资源
      最近更新 更多