I want to fail the build pipeline if a single test failed with azure pipelines.
Azure can successfully detect that my tests entered a failed state however it gives a success state to the entire build pipeline:
The question is how to make azure give a failed build state if the tests stage failed?
Here's my azure-pipelines.yml :
# Build ASP.NET Core project using Azure Pipelines
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core?view=vsts
pool:
vmImage: 'Ubuntu 16.04'
variables:
buildConfiguration: 'Release'
steps:
- script: |
dotnet build --configuration $(buildConfiguration)
dotnet test dotnetcore-tests --configuration $(buildConfiguration) --logger trx
dotnet publish --configuration $(buildConfiguration) --output $BUILD_ARTIFACTSTAGINGDIRECTORY
- task: PublishTestResults@2
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
- task: PublishBuildArtifacts@1
Azure Pipelines combines continuous integration (CI) and continuous delivery (CD) to test and build your code and ship it to any target. Continuous Integration (CI) is the practice used by development teams of automating merging and testing code.
Select the test(s) you want to run, open the Run menu, and choose Run test. The test binaries for these tests must be available in the build artifacts generated by your build pipeline.
Stages filters for pipeline resource triggers requires Azure DevOps Server 2020 Update 1 or greater. You can trigger your pipeline when one or more stages of the triggering pipeline complete by using the stages filter. If you provide multiple stages, the triggered pipeline runs when all of the listed stages complete.
However, if you pause a running Stream pipeline job, the current state of the job is saved and the job is gracefully stopped at that point. When the resume command is issued, a new job is started to restart the Pipeline Version from the previously saved state.
The original answer didn't work for me, but it looks like there was a lot of discussion on this, and there's now a failTaskOnFailedTests
param for the task. That seems to work.
- task: PublishTestResults@2
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
failTaskOnFailedTests: true
I'm still surprised this wasn't default behavior.
Untick the below-highlighted option
Try to add failOnStandardError: 'true'
in the task inputs:
- task: PublishTestResults@2
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
failOnStandardError: 'true'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With