1
votes

I have a build pipeline in Azure DevOps for a ASP.NET Core app, and a want use it with a criteria to approve a pull requests.

steps:
      - script: dotnet restore
        displayName: 'Run command: dotnet restore'

      - script: >
                dotnet test 
                /p:CollectCoverage=true 
                /p:CoverletOutputFormat=cobertura 
                /p:Threshold=80 
                /p:ThresholdStat=total 
                /p:Exclude="[*xunit.*]*"
        displayName: 'Run command: dotnet test'

I want when code coverage (using coverlet) don't pass, the build fails. but despite the acceptance criteria do not pass, even a log message is generated, the step runs successfully.

coverlet.msbuild.targets(41,5): error : The total line coverage is below the specified 80 coverlet.msbuild.targets(41,5): error : The total branch coverage is below the specified 80 coverlet.msbuild.targets(41,5): error : The total method coverage is below the specified 80

It's possible force a fail in this case?

1
Try to add failOnStderr: true in the dotent test taskShayki Abramczyk
i try, but it did not work. I think this message is not considered a failure.Nelson Baggio
In the logs the message is in red color or white color?Shayki Abramczyk
In my terminator console, red, but in azure devops console, white.Nelson Baggio

1 Answers

2
votes

Try to run the tests with DotNetCoreCLI@2 task and not with the simple script:

- task: DotNetCoreCLI@2
  displayName: 'dotnet test'
  inputs:
    commands: test
    projects: 'path/to/tests/projects'
    arguments: 'p:CollectCoverage=true
 /p:CoverletOutputFormat=cobertura /p:Threshold=80
 /p:ThresholdStat=total /p:Exclude="[*xunit.*]"'