Gitlab Coverage test on SonarCloud

i need help with this . …

i need to show coverage report on GitLab and also in sonarcloud

here’s my code below

sonarcloud-check:
  stage: sonar
  image: mcr.microsoft.com/dotnet/sdk:8.0
  cache:
    key: "$CI_JOB_STAGE-$CI_COMMIT_REF_SLUG"
    paths:
      - .sonar/cache
  before_script:
    - export PATH="$PATH:/root/.dotnet/tools"
  script:
    - dotnet tool update --global dotnet-sonarscanner
    - dotnet tool update --global dotnet-coverage
    - dotnet tool update --global dotnet-reportgenerator-globaltool
    - dotnet sonarscanner begin /k:"$SONAR_PROJECT_KEY" /o:"$SONAR_ORG" /d:sonar.login="$SONAR_TOKEN"
      /d:sonar.qualitygate.wait=true /d:sonar.gitlab.max_major_issues_gate=0
       /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
    - dotnet build Project.sln
    - dotnet-coverage collect "dotnet test Project.sln" -f xml -o "coverage.xml"
    - dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"
  artifacts:
    when: always
    expire_in: 2 week
    paths:
      - coverage.xml
    reports:
      junit:
        - coverage.xml

Hi,

I guess the coverage isn’t showing up? (I know that’s implicit here, but… :sweat_smile:)

What are you seeing? Is coverage showing up as a - or 0% in SonarCloud? (BTW, we can’t help you with showing coverage directly in GitLab.)

 
Ann

Many thanks Ann,

So for the most runs it shows 0.0% and sometimes it shows on a branch and does not show on a target branch after a merge

and yes the CI is on GitLab buh i need to show the report on Sonarcloud

Hi,

Can you provide a verbose analysis log, please?

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@1
            inputs:
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'MSBuild'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
                sonar.verbose=true
        
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d

or

dotnet build -v:d

 
Thx,
Ann