Nicole Phillips
Nicole Phillips

Reputation: 763

Azure devops fails on warnings with 'fail on standard error' set to true

I have an inline PowerShell task on an Azure DevOps ci pipeline that requires any warnings to be ignored, however, any errors fail the task and stop the build.

I had originally set the 'fail on standard error' to true, but because all errors and warnings are written to stderr this will fail on any warning.

The below I tried with 'fail on standard error' to false. Which although noticed the error did not fail the task.

sfdx partial:lsapp:build
if ($exitCode -ne 0)
{    
Write-Output (\"[Error] Failing task since return code was {0} while expected 0.\" -f $exitCode)
}
[Environment]::Exit($exitCode)

Any help would be greatly appreciated.

Upvotes: 2

Views: 6078

Answers (2)

Filippos Karapetis
Filippos Karapetis

Reputation: 4652

Based on your scenario, you could change the Azure DevOps pipeline so that it doesn't stop when an error occurs - this is the "continue on error" flag, which can be set as follows in a YAML Azure DevOps pipeline:

- task: "Test@1"
  continueOnError: true

and for classic pipelines, you can check the "Continue on error" checkbox.

For more information, you can read through this Azure DevOps documentation page: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/tasks?view=azure-devops&tabs=yaml

Upvotes: 1

Manuel Batsching
Manuel Batsching

Reputation: 3606

It seems that the salesforce cli writes warnings to stderr. In that case there is not much you can do to separate warnings and errors in the inline PowerShell task in which you execute the salesforce command.

But if you want to fail the pipeline based on an exit code, you can still use a workaround: Save the exit code in a pipeline variable and evaluate it in a separate task that has failOnStderr: true and fails if needed:

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      #sfdx partial:lsapp:build
      $exitCode = 1    # Setting this for testing
      Write-Host "##vso[task.setvariable variable=sfdxExitCode;]$exitCode"

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      $exitCode = $(sfdxExitCode)
      if ($exitCode -ne 0)
      {    
          Write-Error ("Failing task since return code was {0} while expected 0." -f $exitCode)
      }
    failOnStderr: true

Upvotes: 5

Related Questions