bash - .net 核心“dotnet build”命令不会因错误而中断 Azure 构建管道 (bash)
问题描述
我有一个带有 CentOS 代理的 Azure 管道。管道不会在构建失败时中断。这是管道 yaml 配置的一部分:
- bash: |
dotnet --version
dotnet build $(Build.Repository.LocalPath)/ProjA -c Release -r linux-x64
dotnet build $(Build.Repository.LocalPath)/ProjB -c Release -r linux-x64
failOnStderr: true
displayName: build
env:
DOTNET_CLI_HOME: /tmp
如何使其因构建错误而失败?
构建日志:
##[section]Starting: build
==============================================================================
Task : Bash
Description : Run a Bash script on macOS, Linux, or Windows
Version : 3.151.2
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash
==============================================================================
Generating script.
========================== Starting Command Output ===========================
[command]/usr/bin/bash --noprofile --norc (path)be642b86-51b1-44c5-8727-71cc18ec0678.sh
2.2.300
Microsoft (R) Build Engine version 16.1.76+g14b0a930a7 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 2.22 sec for (ProjA)
...
Build FAILED.
...
7 Warning(s)
3 Error(s)
Time Elapsed 00:00:05.73
Microsoft (R) Build Engine version 16.1.76+g14b0a930a7 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 568.52 ms for (ProjB)
...
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:03.17
##[section]Finishing: build
解决方案
是的,我已经看到我在 Linux 代理上运行的构建发生了类似的事情。
Windows 有 %ERRORLEVEL% 来捕获最后执行的命令或脚本的返回/退出代码,在查询您将知道是否继续执行其余部分时。同样,您可以尝试做的是从您在 CentOS 机器上执行的命令echo $?
(stderr
这意味着任务将失败,因为您将failOnStderr
arg 设置为true
,从而导致构建中断。还有一些任务控制选项continueOnError
,我们可以利用它们来定义这种行为:
以下是一些有趣的相关读物:
- 在 dotnet core 中捕获本机异常
- https://docs.microsoft.com/en-us/azure/devops/pipelines/process/tasks?view=azure-devops&tabs=yaml#task-control-options
希望这可以帮助。
推荐阅读
- octobercms - 我想更改状态列 - 在 columns.yaml 中的 CMS 10 月中使用颜色
- javascript - 尝试从 ajax(Wordpress 插件)将 FormData 中的 Blob 发布到 php 时出现 400(错误请求)
- sharepoint-2013 - Office 加载项 word 文档关闭事件中的任务窗格
- c# - 如何通过交互式提供凭据从 asp.net Web 表单应用程序连接到 Azure Active Directory?
- r - 尝试使用负二项分布和线性参数化 V = mu(1 + phi) in brms in r
- javascript - 在 ISO 日期获取FullYear
- cloud - 云计算和无服务器计算有什么区别?
- r - R:有没有办法对杂乱无章的数据进行排序,从长到宽,当它跨变量移动时,进入一个逻辑键:值列?
- python - MatPlotLib 图表未显示
- css - 自定义 SB Admin 2 主题