【问题标题】:Can i fail the jenkins build of .net project if during "dotnet build" i have some compiler warning?如果在“dotnet build”期间我有一些编译器警告,我可以让 .net 项目的 jenkins 构建失败吗?
【发布时间】:2025-12-02 02:35:01
【问题描述】:

如果在执行“dotnet build”期间,我想使 Jenkins 构建失败,则会出现编译器警告。 我尝试在“构建后步骤”中使用“记录编译器警告...”。 我们有用于项目代码样式的 .editorconfig 文件。因此,如果我们将在此文件中注意到警告,则我的 Jenkins 构建一定失败。

【问题讨论】:

标签: .net jenkins continuous-integration compiler-warnings


【解决方案1】:

您的问题与 Jenkins 无关。如果脚本返回错误退出代码,jenkins 将失败。

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

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

【讨论】:

    【解决方案2】:

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

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

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

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

    【讨论】:

      最近更新 更多