问题描述
我正在寻找一种方法来在我的 Jenkins 流水线脚本中记录 shellcheck 的违规结果。到目前为止,我无法找到一些东西。对于其他工具(Java、Python),我使用的是 Warnings Next Generation,但它似乎还不支持 shellcheck。我希望在我的 Jenkins 工作仪表板中可视化违规行为。有没有人有这方面的经验?或者也许是一个准备好使用警告 NG 的自定义工具?
解决方法
我自己确实找到了可行的解决方案。就像评论中建议的那样,拼写检查提供了 checkstyle 格式,可以使用警告 NG 对其进行解析和可视化。以下管道阶段定义工作正常。
stage('Analyze') {
steps {
catchError(buildResult: 'SUCCESS') {
sh """#!/bin/bash
# The null command `:` only returns exit code 0 to ensure following task executions.
shellcheck -f checkstyle *.sh > shellcheck.xml || :
"""
recordIssues(tools: [checkStyle(pattern: 'shellcheck.xml')])
}
}
}
运行构建会生成一个很好的趋势图,如下所示。