Priyanka Sharma
Priyanka Sharma

Reputation: 131

How can I fail the pipeline run in Azure devops, once the failed test percentage is higher than threshold

I want the pipeline to fail if the threshold of failing test is more than 70%, how should I implement it in Azure Devops Pipeline. The test are running with mvn install command and test script.

Upvotes: 0

Views: 1231

Answers (1)

Kevin Lu-MSFT
Kevin Lu-MSFT

Reputation: 35544

Update:

Based on your reply, you need to fail the pipeline based on the number of failed tests.

There is no out-of-box method can achieve it in Azure Pipeline.

I suggest that you can check the result based on the Test Result file(XML file) created by Maven test.

You can use the Maven task to run the test and generate the test xml file.

Then you can use PowerShell task to determine if the pipeline can pass.

Here is an example:

steps:
- task: Maven@3
  displayName: 'Maven pom.xml'
  inputs:
    goals: test command
    testResultsFiles: '$(build.artifactstagingdirectory/surefire-reports/TEST.xml'
  continueOnError: true

- powershell: |
   [xml]$xml= Get-Content $(build.artifactstagingdirectory)\surefire-reports\Test.xml
   $failures= $xml.testsuite.failures
   
   If($failures -gt xx)
   
   {
   
   Write-host "##vso[task.complete result=failed;]DONE"
   
   }
  displayName: 'PowerShell Script'

Upvotes: 2

Related Questions