如果在 "dotnet build" 期间我有一些编译器警告,我可以使 .net 项目的 jenkins 构建失败吗?

Can i fail the jenkins build of .net project if during "dotnet build" i have some compiler warning?

如果在执行过程中 "dotnet build",我想使 Jenkins 构建失败,将会出现编译器警告。 我尝试在 "Post-build step" 中使用 "Record the compiler warning..."。 我们的项目代码风格有 .editorconfig 文件。因此,如果我们在此文件中出现警告,则我的 Jenkins 构建一定失败了。

你的问题与詹金斯无关。如果脚本 returns 出现错误退出代码,jenkins 将失败。

为此,您可以在可执行文件上指定一些选项。看起来 /WarnAsError 应该可以解决问题。但是我在 github 上看到这可能行不通 https://github.com/dotnet/core-sdk/issues/1708

或者你可以执行一个像这样的外部程序 https://github.com/editorconfig-checker/editorconfig-checker/ 我没试过,但看起来它可以完成这项工作 ;)

作为 "ultimate" 解决方案,您可以使用日志解析器插件: https://wiki.jenkins.io/display/JENKINS/Log+Parser+Plugin。 它具有根据控制台日志中的消息使作业失败的功能。

您可能应该考虑的另一件事是您如何 运行 'dotnet build' 命令。 Jenkins 考虑了整个脚本的最新退出代码。所以如果你 运行 像

dotnet build ...;
rm -R ...;

Jenkins 使用 rmdir 命令的退出代码。