Sonar properties are not used by Azure Devops

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    Azure SonarQubePrepare/Plugin 4.8.0
    SonarQube Community Edition Version 8.0 (build 29455)

  • what are you trying to achieve
    Hello, I am trying to get dotcover code coverage and nunit tests to be part of the sonarqube analysis on an azure devops pipeline.

  • what have you tried so far to achieve this
    I have run tests and code coverage using a powershell script.
    The cobertura converted dotCover results are stored in cobertuta/coverage.xml relative to rootfolder.
    Nunit files are generated as *nunit.dll.xml in different folders.

I tried adding properties to the task in azure

 - task: SonarQubePrepare@4
    inputs:
      SonarQube: '****'
      scannerMode: 'MSBuild'
      projectKey: '***'
      projectName: '***'
      extraProperties: |
        sonar.exclusions=**/*.xml
        sonar.cobertura.reportPath=cobertura/coverage.xml
        sonar.cs.nunit.reportsPaths=**/*nunit.dll.xml

I also tried adding a sonar-project.properties file in the root folder of the repository

sonar.exclusions=**/*.xml
sonar.cobertura.reportPath=cobertura/coverage.xml
sonar.cs.nunit.reportsPaths=**/*nunit.dll.xml

And I tried setting the same values on the sonarqube server in the project. Tried all at the same time and one by one. But when I run the task it always says no unit tests found and no code coverage found. I also tried adding the cobertura report to the temp directory on the agent but same issue.

2020-01-17T09:52:28.4956920Z ##[section]Starting: SonarQubeAnalyze
2020-01-17T09:52:28.5163227Z ==============================================================================
2020-01-17T09:52:28.5163313Z Task         : Run Code Analysis
2020-01-17T09:52:28.5163356Z Description  : Run scanner and upload the results to the SonarQube server.
2020-01-17T09:52:28.5163403Z Version      : 4.8.0
2020-01-17T09:52:28.5163439Z Author       : sonarsource
2020-01-17T09:52:28.5163492Z Help         : This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
2020-01-17T09:52:28.5163848Z ==============================================================================
2020-01-17T09:52:29.1371027Z [command]E:\agent\_work\_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.8.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe end
2020-01-17T09:52:30.1034460Z SonarScanner for MSBuild 4.7.1
2020-01-17T09:52:30.1035600Z Using the .NET Framework version of the Scanner for MSBuild
2020-01-17T09:52:30.1414338Z Post-processing started.
2020-01-17T09:52:31.0973059Z 10:52:31.096  Fetching code coverage report information from TFS...
2020-01-17T09:52:31.0988253Z 10:52:31.098  Attempting to locate a test results (.trx) file...
2020-01-17T09:52:31.2757152Z 10:52:31.275  Looking for TRX files in: E:\agent\_work\21\TestResults
2020-01-17T09:52:31.2760808Z 10:52:31.275  No test results files found
2020-01-17T09:52:31.4606148Z 10:52:31.46  Did not find any binary coverage files in the expected location.
2020-01-17T09:52:31.4616521Z 10:52:31.461  Falling back on locating coverage files in the agent temp directory.
2020-01-17T09:52:31.4625976Z 10:52:31.462  Searching for coverage files in E:\agent\_work\_temp
2020-01-17T09:52:31.4635987Z 10:52:31.463  No coverage files found in the agent temp directory.
2020-01-17T09:52:33.9421742Z WARNING: File 'E:\agent\_work\21\s\XXXX' does not exist.
2020-01-17T09:52:34.1390048Z Calling the SonarQube Scanner...
2020-01-17T09:52:34.4608295Z INFO: Scanner configuration file: E:\agent\_work\_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.8.0\classic-sonar-scanner-msbuild\sonar-scanner-4.1.0.1829\bin\..\conf\sonar-scanner.properties
2020-01-17T09:52:34.4654950Z INFO: Project root configuration file: E:\agent\_work\21\.sonarqube\out\sonar-project.properties
2020-01-17T09:52:34.6060756Z INFO: SonarQube Scanner 4.1.0.1829
2020-01-17T09:52:34.6061269Z INFO: Java 1.8.0_231 Oracle Corporation (64-bit)
2020-01-17T09:52:34.6061491Z INFO: Windows 10 10.0 amd64
2020-01-17T09:52:35.5222408Z INFO: User cache: C:\Users\admin\.sonar\cache
2020-01-17T09:52:36.2219211Z INFO: SonarQube server 8.0.0
2020-01-17T09:52:36.2233491Z INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
2020-01-17T09:52:36.5969186Z WARN: SonarScanner will require Java 11+ to run starting in SonarQube 8.x
2020-01-17T09:52:36.6935444Z INFO: Load global settings
2020-01-17T09:52:37.4791816Z INFO: Load global settings (done) | time=785ms

Any idea what I am missing?

Can I log the properties of the sonarqube run somehow?

Hi @kristian.mo ,

I think that your are mixing somehow the possibilits of the different properties available for tests executions and coverage.

As per the SonarQube doc here are the supported property around C# projects :

For coverage :

sonar.cs.vscoveragexml.reportsPaths
sonar.cs.dotcover.reportsPaths
sonar.cs.opencover.reportsPaths

For unit test executions (will show the number of unit tests executed / discovered).

sonar.cs.vstest.reportsPaths
sonar.cs.nunit.reportsPaths
sonar.cs.xunit.reportsPaths

Any other provided will be ignored.

Mickaël

Thank you for helping with the correct properties.

Got it working for nunit with this:

       inputs:
        SonarQube: '***'
        scannerMode: 'MSBuild'      
        projectKey: '*'
        projectName: '*'   
        extraProperties: |
          sonar.exclusions=**/*.java, **/*.jar, **/*.xml, 3rdPartyLibraries/**, UIAutomationTesting/**, 
packages/**, CM/**
          sonar.cs.nunit.reportsPaths=$(Agent.BuildDirectory)/**/*nunit.dll.xml

Now the 1 million dollar question is what dotcover format is compatible with sonarqube?

XML or DetailedXML gives missing <!DOCTYPE HTML error, HTML it cannot find.

For anybody else.

This devops task

  - task: SonarQubePrepare@4
    inputs:
      SonarQube: '**'
      scannerMode: 'MSBuild'      
      projectKey: '*'
      projectName: '*'   
      extraProperties: |
        sonar.exclusions=**/*.java, **/*.jar, **/*.xml, 3rdPartyLibraries/**, UIAutomationTesting/**, packages/**, CM/**
        sonar.cs.dotcover.reportsPaths=$(Agent.BuildDirectory)/**/*coverage.html
        sonar.cs.nunit.reportsPaths=$(Agent.BuildDirectory)/**/*nunit.dll.xml

and this dotcover made it work

dotCover.exe analyse /targetexecutable=".\packages\NUnit.ConsoleRunner.3.10.0\tools\nunit3-console.exe" /targetarguments="UnitTest.dll --result=nunit.dll.xml --noheader" /output=coverage/coverage.html /reporttype=HTML
1 Like

The SonarQube code analysis task in our build pipeline yaml getting failed with below error.

Not sure from where the sonarqube is taking the location from . its taking the users home directory now. /home/vowne. We have enough space in other location and would need to change the sonarqube temp location to there.

Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.8.0.2131:sonar on project: Unable to load component interface org.sonar.api.utils.TempFolder: Failed to create temporary folder in /home/vowne/.sonar: /home/vowne/.sonar/.sonartmp_xxxxxxx: No space left on device

@mickaelcaro @kristian.mo

Any suggestion on the above issue… can we set any additional property in the sonarqube pligin task part to change the temp directory creation from the /home/vowne to /data

- task: SonarQubePrepare@4
    inputs:
      SonarQube: 'Sonarqube'
      ScannerMode: 'Other'
      extraProperties: |
          sonar.projectName=${{ parameters.myName }}
          sonar.coverage.jacoco.xmlReportPaths=$(System.DefaultWorkingDirectory)/coverage-report/target/site/jacoco-aggregate/jacoco.xml
          sonar.userHome=$(System.DefaultWorkingDirectory)