4
votes

I have setup a Pull Request Pipeline in Azure DevOps that will include a SonarQube Analyse.

The pipeline build, test and analyse the .net core projects. After the build job, SonarQube contains the Analyse results, but not the coverage information.

Test Framework: MSTest

SonarQube: Developer Edition Version 8.0 (build 29455)

PullRequest.yml

pool:
  vmImage: 'windows-latest'

steps:
- script: echo Pull Request Pipeline
  displayName: 'Pull Request Pipeline'

- task: SonarQubePrepare@4
  inputs:
    SonarQube: 'SonarQube Connection'
    scannerMode: 'MSBuild'
    projectKey: 'ProjectKey'
    projectName: 'ProjectName'
    extraProperties: |
      sonar.scm.exclusions.disabled
      sonar.language=csharp
      sonar.log.level=TRACE
      sonar.verbose=true
      sonar.pullrequest.base=master
      sonar.pullrequest.key=$(System.PullRequest.PullRequestId)
      sonar.pullrequest.branch=$(Build.SourceBranchName)
      sonar.cs.vscoveragexml.reportsPaths=**\*.coveragexml

- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '-c release'

- task: DotNetCoreCLI@2
  inputs:
    command: 'test'
    projects: '**/*.csproj'
    arguments: '-c release --no-build --collect:"Code Coverage"'

- task: SonarQubeAnalyze@4

- task: SonarQubePublish@4
  inputs:
    pollingTimeoutSec: '300'

dotnet test creates a coverage file and CodeCoverage.exe creates a coveragexml file, but SonarQube doesn't find the coveragexml file.

Microsoft (R) Coverage Collection Tool Version 16.0.30319.3002


Copyright (c) Microsoft Corporation.  All rights reserved.




Results File: d:\a\_temp\VssAdministrator_fv-az623_2019-12-05_13_18_24.trx

Attachments:
  d:\a\_temp\ea5c681a-654c-4370-b748-d7264b53a0d9\VssAdministrator_fv-az623_2019-12-05.13_18_22.coverage
Test Run Successful.

... 

Config file: d:\a\1\.sonarqube\conf\SonarQubeAnalysisConfig.xml
13:18:27.568  Attempting to locate the CodeCoverage.exe tool...
13:18:27.583  Attempting to locate the CodeCoverage.exe tool using setup configuration...
13:18:27.833  Code coverage command line tool: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe
13:18:27.849  Property 'sonar.cs.vstest.reportsPaths' provided, skipping the search for TRX files in default folders...
13:18:27.849  Did not find any binary coverage files in the expected location.
13:18:27.849  Falling back on locating coverage files in the agent temp directory.
13:18:27.849  Searching for coverage files in d:\a\_temp
13:18:27.849  All matching files: count=2
13:18:27.849    d:\a\_temp\ea5c681a-654c-4370-b748-d7264b53a0d9\VssAdministrator_fv-az623_2019-12-05.13_18_22.coverage
13:18:27.849    d:\a\_temp\VssAdministrator_fv-az623_2019-12-05_13_18_24\In\fv-az623\VssAdministrator_fv-az623_2019-12-05.13_18_22.coverage
13:18:27.849  Unique coverage files: count=1
13:18:27.849    d:\a\_temp\ea5c681a-654c-4370-b748-d7264b53a0d9\VssAdministrator_fv-az623_2019-12-05.13_18_22.coverage
13:18:27.958  Executing file C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe
  Args: analyze /output:d:\a\_temp\ea5c681a-654c-4370-b748-d7264b53a0d9\VssAdministrator_fv-az623_2019-12-05.13_18_22.coveragexml d:\a\_temp\ea5c681a-654c-4370-b748-d7264b53a0d9\VssAdministrator_fv-az623_2019-12-05.13_18_22.coverage 
  Working directory: d:\a\_temp\ea5c681a-654c-4370-b748-d7264b53a0d9
  Timeout (ms):60000
  Process id: 5452
13:18:28.161  Process returned exit code 0

...

13:18:57.004 INFO: Sensor C# [csharp] (done) | time=529ms
13:18:57.004 INFO: Sensor C# Tests Coverage Report Import [csharp]
13:18:57.004 WARN: Could not find any coverage report file matching the pattern 'd:\a\1\b\**\*.coveragexml'.
13:18:57.004 INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=0ms
13:18:57.004 INFO: Sensor C# Unit Test Results Import [csharp]
13:18:57.019 INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=15ms

What is wrong with the yml pipeline?

1
The coveragexml file is not found with the search pattern d:\a\1\b\**\*.coveragexml. There is a coveragexml at d:\a\_temp\ea5c681a-654c-4370-b748-d7264b53a0d9\VssAdministrator_fv-az623_2019-12-05.13_18_22.coveragexmlriQQ

1 Answers

2
votes

The reportsPaths was wrong.

This works for me:

sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)\**\*.trx
sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)\**\*.coveragexml