如何在 jenkins 中显示 npm 审计的结果并使构建失败

dag*_*da1 5 npm jenkins npm-audit

我想运行 npm 命令npm audit作为 ci 构建的一部分,并以某种方式在 jenkins ci 构建中显示输出。

如果发现严重漏洞,我想通过返回非零退出代码来使当前构建失败。

sme*_*elm 2

我不知道有什么插件可以实现此目的,但一些手动解析可能会起作用(如果您使用的是管道)。

def output = sh script: "npm audit", returnStdout: true
def summary = output.split("\n")[-1] //get the summary from the last line
...
Run Code Online (Sandbox Code Playgroud)

然后,您可以使用一些正则表达式或其他字符串操作来查找关键之后的数字。您还可以使用 archiveArtifacts 将整个输出保存在构建历史记录中。