如何使用 Junit 在 Jenkins 中显示 Angular Lint 输出?

use*_*861 1 junit lint jenkins angular-cli jenkins-declarative-pipeline

如何在 Jenkins 中显示“npm lint”结果?我知道如何在 Jenkins 中显示“pytest”结果:

  1. 像这样运行 pytest: pytest --junitxml=./path/to/pytestFile.xml ./path/to/code
  2. 运行这个 Jenkins 命令: junit testResults: "./path/to/pytestFile.xml"

一旦我这样做了,我的测试结果就会出现在 Jenkins 的“测试结果”窗口中。我想对我的 angular lint 结果做类似的事情。我尝试这样做,但没有用:

  1. 像这样运行 linter: npm lint --junitxml=./path/to/lintFile.xml
  2. 运行这个 Jenkins 命令: junit testResults: "./path/to/lintFile.xml"

问题是 npm 没有 --junitxml 开关。我怎样才能做到这一点?我正在使用 Jenkins 声明式管道。

Sto*_*ica 5

JUnit 是测试结果的格式,而不是 lint 结果。尝试使用它是没有意义的。

最好使用的插件是Warnings Next Generation。它tslint列为受支持的格式。

steps {
  sh 'npm run-script --silent -- ng lint --format=checkstyle >checkstyle-result.xml'
}
post {
  always {
    recordIssues tool: tsLint(pattern: 'checkstyle-result.xml'),
                 enableForFailure: true
  }
}
Run Code Online (Sandbox Code Playgroud)

如果您的工作区中有多个项目,您可能会受到#14659 的影响。指定单个项目或通过管道传输输出split -l 1

如您所见,您将获得一份专门针对 TSLint 的报告,与其他分析问题和测试结果分开。它还理解不同的严重性级别,这是无法用 JUnit 表达的。

为 TSLint、测试结果和漏洞生成图表

  • +1 这个解决方案实际上使用了“ng lint”,而不是顽固的OP直接使用“tslint”的解决方案。这实际上回答了问题。OP 解决方案回答了不同的问题。 (2认同)