How to fail the build pipeline if “Tests Failed” in azure pipelines?

ぐ巨炮叔叔 提交于 2020-04-10 08:10:32

问题


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

回答1:


Try to add failOnStandardError: 'true' in the task inputs:

- task: PublishTestResults@2
  inputs:
    testRunner: VSTest
    testResultsFiles: '**/*.trx'
    failOnStandardError: 'true'



回答2:


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.



来源:https://stackoverflow.com/questions/52789635/how-to-fail-the-build-pipeline-if-tests-failed-in-azure-pipelines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!