如果“测试失败",如何使构建管道失败?在蔚蓝的管道中?

如果“测试失败

问题描述:

如果单个测试因天蓝色管道失败,我想使构建管道失败.

I want to fail the build pipeline if a single test failed with azure pipelines.

Azure可以成功检测到我的测试进入了失败状态,但是它为整个构建管道提供了成功状态:

Azure can successfully detect that my tests entered a failed state however it gives a success state to the entire build pipeline:

问题是,如果测试阶段失败,如何使azure给出失败的构建状态?

The question is how to make azure give a failed build state if the tests stage failed?

这是我的 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

原始答案对我不起作用,但似乎有 failTaskOnFailedTests 该任务的参数.似乎可行.

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.