What am I doing wrong in tei Azure devops pipeline?

Hallo together ,
accedently I have gotten the task to display the code coverage to an sonar.cloud results page.
The code coverage is displayed in the coverage Tab in the Pipleine tabs,
but not in the Sonarclod quality gate.
i have the following prepare task

  - task: SonarCloudPrepare@1
      condition: and(succeeded(), eq(variables.performSonarAnalysis, 'true'))
      inputs:
        SonarCloud: 'SonarCloud'
        organization: 'ksca'
        scannerMode: 'MSBuild'
        projectKey: 'KSCA_OurWCS'
        projectName: 'OurWCS'
        extraProperties: |
          sonar.cobertura.reportPaths='$(Agent.TempDirectory)/**/coverage.cobertura.xml'
          sonar.exclusions=**/obj/**,**/*.dll
          sonar.cs.xunit.reportsPaths=${Agent.TempDirectory}/**/XUnit.TestResults.xml
          #sonar.cs.opencover.reportsPaths=${Agent.WorkFolder}/coverage/$(OPENCOVER_OUTPUT)
          sonar.cs.opencover.reportsPaths=${Agent.WorkFolder}/coverage/opencoverCoverage.xml
          sonar.sourceEncoding=UTF-8 
          sonar.verbose=true

in the test step

 - task: DotNetCoreCLI@2
      displayName: 'dotnet test'
      inputs:
        command: 'test'
        projects: '**/*.csproj'
        #arguments:   '--no-restore --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=$(Build.SourcesDirectory)/coverage/'
        arguments: '--configuration $(BuildConfiguration) --no-build /p:CollectCoverage=true  /p:settings=.runsettings.xml /p:CoverletOutputFormat=opencover /p:CoverletOutput=$(Agent.WorkFolder)/coverage/$(OPENCOVER_OUTPUT) /p:MergeWith=$(Agent.WorkFolder)/coverage/  --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura'
        publishTestResults: true

during test step in the logs there are is many times appearing entries like

Calculating coverage result...
  Generating report '/home/vsts/work/coverage/opencoverCoverage.xml'

then we have a step that creates and puplishes code coverage to pipeline


  # First install the tool on the machine, then run it
    - script: |
        dotnet tool install -g dotnet-reportgenerator-globaltool  --version 5.1.13
        reportgenerator -reports:$(Agent.WorkFolder)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CoverageResults -reporttypes:'HtmlInline_AzurePipelines;Cobertura'
      displayName: Create code coverage report

but in the analyze step
i get the following

6 WARN: Could not find any coverage report file matching the pattern '/coverage/opencoverCoverage.xml'

Wht am I doing wrong ?

TIIA
Martin

Hi,

Welcome to the community!

The difference between your property value:

And the error message:

Seems to be that ${Agent.WorkFolder} evaluated to empty string. Try making the path relative to the project root:

sonar.cs.opencover.reportsPaths=coverage/opencoverCoverage.xml
(Note the lack of the leading / there).

 
HTH,
Ann

Hi Ann , thank for your rersponse,
It was in fact something wrong with the variables.

We fixed this and now everything seems to be OK.

00:17:49.952 DEBUG: Analyzing coverage with wildcardPatternFileProvider with base dir ‘/home/vsts/work/1/.’ and file separator ‘/’.

00:17:49.953 DEBUG: Pattern matcher extracted prefix/absolute path ‘/home/vsts/work/coverage/opencoverCoverage.xml’ from the given pattern ‘/home/vsts/work/coverage/opencoverCoverage.xml’.

00:17:49.953 DEBUG: Pattern matcher returns a single file: ‘/home/vsts/work/coverage/opencoverCoverage.xml’.

00:17:49.953 DEBUG: The current user dir is ‘/home/vsts/work/1’.

00:17:49.953 INFO: Parsing the OpenCover report /home/vsts/work/coverage/opencoverCoverage.xml

Kind regards Martin

Hi Martin,

Thanks for the follow-up. I’m glad you got this working!

 
Ann