Azure DevOps checkout to sub-folder gets mismatching paths in coverage

  • ALM used - Azure DevOps
  • CI system used - Azure DevOps
  • Scanner command - Azure Task with the following yaml for prepare:
- task: SonarCloudPrepare@1
  inputs:
    SonarCloud: 'MySonarLink'
    organization: 'myorg'
    scannerMode: 'CLI'
    configMode: 'file'
    configFile: '${{ parameters.pythonRoot }}/sonar-project.properties'

This job needs to check out multiple repositories so we provide the pythonRoot here to specify the folder that the python code was checked out to so that the sonar-project.properties file can be properly located.

  • Language: Python
  • Error observed
INFO: Scanner configuration file: /home/vsts/work/_tasks/SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1/1.29.1/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/vsts/work/1/s/<REDACTED>/sonar-project.properties
INFO: Analyzing on SonarCloud
...
##[error]ERROR: Invalid value of sonar.tests for <REDACTED>

  • Steps to reproduce
    Configure sonar.sources / sonar.tests for src folder which is relative to where the sonar-project.properties file
    Run the pipeline
  • Potential workaround
    Tried using the relative checkout path in sonar-project.properties - i.e. /src and this will run however when run in this mode the source paths for coverage are not found because the paths in the coverage.xml output file are relative to the repo. root.

The docs indicate the paths should be configurable relative to the sonar-project.properties file however this clearly doesn’t work as expected when using the Azure DevOps pipeline task.

Hi,

Welcome to the community!

A lot has been redacted or elided here, so it’s difficult to be clear about what’s going on.

Some underlying assumptions with analysis are:

  • Analysis is fired from project root
  • The properties file is in project root
  • Paths in the properties file point to directories that are in project root (recursive)

You seem to be firing analysis from a directory that’s not project root (based on configFile: '${{ parameters.pythonRoot }}/sonar-project.properties') and I think that may be part of the complication here.

On a side note, another assumption is that tests and source files are stored separately. The fact that they’re both pointing to src(?) probably isn’t helping.

 
HTH,
Ann

Hi,

Thanks for the response and your help. We managed to fix the underlying issue by setting sonar.projectBaseDir to the sub-folder that the repository was checked out to via the sonar-project.properties file. We couldn’t see any way of specifying to the azure tasks where the project root actually was so made the assumption it is calculating project root based on a default single repository checkout within an azure pipeline.

Thanks
Carl

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.