0

I have an Azure pipeline with a CentOS agent. The pipeline do not break on build fail. Here is a part form the pipeline yaml configuration:

- 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

How can I make it fail on build errors?

Build log:

##[section]Starting: build
==============================================================================
Task         : Bash
Description  : Run a Bash script on macOS, Linux, or Windows
Version      : 3.151.2
Author       : Microsoft Corporation
Help         : https://learn.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
Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30
user2809176
  • 1,042
  • 12
  • 29

1 Answers1

1

Yes, I've seen similar things happen with my builds running on Linux agents.

Windows has %ERRORLEVEL% to catch the return/exit code of the last executed command or script, upon querying which you would know whether or not to proceed with the rest of execution. Similarly, what you could try doing is get the right exit code from your executed command on the CentOS machine (echo $?) and pipe the output to stderr if something does go wrong indeed.

This would then mean that the task would fail as you have the failOnStderr arg set to true, resulting in breaking the build. There are also some task control options like continueOnError that we could utilize to define this behaviour:

task control options

Here are some interesting related reads:

Hope this helps.

Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30