Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BuildQualityChecks fails and Sonar do not match in coverage. #243

Open
borisgonzalezrivera opened this issue Sep 13, 2024 · 1 comment
Open
Assignees

Comments

@borisgonzalezrivera
Copy link

I have a program in net 6, in which I run coverage on my local computer, in sonar and BuildQualityChecks they give a value greater than 80%. Then we migrate the project to net 8 and the coverage locally gives greater than 80%, in sonar from the pipeline also greater than 80% but the BuildQualityChecks task gives less than 80%. Attached I show the tasks of the pipeline.

`steps:

  • template: ../spellCheck.yml

  • task: SonarQubePrepare@6
    displayName: 'Prepare analysis on SonarQube'
    condition: and(succeeded(), eq('${{parameters.includeSonar}}', 'true'))
    inputs:
    SonarQube: 'SC-ECP-PRD-SonarQube-AD-True'
    scannerMode: 'MSBuild'
    projectKey: 'True-API-ApiConfigBackend'
    projectName: 'True-API-ApiConfigBackend'
    extraProperties: |
    # Additional properties that will be passed to the scanner,
    # Put one key=value per line, example:
    # sonar.exclusions = /.bin
    sonar.cs.vstest.reportsPaths = $(Agent.TempDirectory)/
    .trx
    sonar.cs.opencover.reportsPaths = $(Agent.TempDirectory)//coverage.opencover.xml
    sonar.coverage.exclusions = /Host.UI/, /Entities/ , /Configuration/Query/
    sonar.exclusions= **/
    .yaml,
    /Dockerfile

  • task: DevOpsEcopetrol.sonar-extension-branch.task-variable.sonar-extension-branch@0
    condition: and(succeeded(), eq('${{parameters.includeSonar}}', 'true'))
    displayName: branch

  • task: DotNetCoreCLI@2
    displayName: Build
    inputs:
    command: build
    projects: "$(functionsProjects)"
    arguments: "--configuration $(buildConfiguration)"

  • task: DotNetCoreCLI@2
    displayName: Run Tests
    inputs:
    command: test
    arguments: '--settings "$(Build.SourcesDirectory)/Develop/Sln Items/Ecp.True.CodeCoverage.NetCore.runsettings" --configuration $(buildConfiguration) --collect "Code coverage"'
    projects: "$(unitTestProjects)"
    publishTestResults: true
    testRunTitle: 'Unit Tests'

  • task: PowerShell@2
    displayName: "Sleep for Code Coverage Merge"
    inputs:
    targetType: "inline"
    script: "Start-Sleep -Seconds 30"

  • task: PublishCodeCoverageResults@2
    displayName: "Publish Code Coverage Results"
    inputs:
    summaryFileLocation: '$(Agent.TempDirectory)/*.trx'
    reportDirectory: '$(Agent.TempDirectory)/**/coverage.opencover.xml'
    failIfCoverageEmpty: true

  • task: BuildQualityChecks@9
    displayName: "Check Code Coverage"
    inputs:
    checkCoverage: true
    coverageFailOption: fixed
    coverageThreshold: $(serverSideUnitTestingThreshold)
    coverageType: "lines"
    buildConfiguration: $(buildConfiguration)
    treat0of0as100: true

  • task: SonarQubeAnalyze@6
    condition: and(succeeded(), eq('${{parameters.includeSonar}}', 'true'))
    displayName: "Run Code Analysis"

  • task: SonarQubePublish@6
    condition: and(succeeded(), eq('${{parameters.includeSonar}}', 'true'))
    displayName: "Publish Quality Gate Result"

  • task: DotNetCoreCLI@2
    displayName: Publish
    inputs:
    command: publish
    publishWebProjects: False
    projects: "$(functionsProjects)"
    arguments: "--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)"
    `

@ReneSchumacher ReneSchumacher self-assigned this Sep 16, 2024
@ReneSchumacher
Copy link
Member

Hi @borisgonzalezrivera,

this is a little strange as all the tools should work based on the same coverage file. Build Quality Checks does not evaluate coverage itself, it simple reads the data from Azure DevOps. So, you should first look at the build summary page and check what value is displayed there:

image

BQC might report slightly different values depending on the coverage type that you are using as some tools evaluate things like branch coverage slightly different (in my case, BQC is reporting 458/509 branches covered (89.9804%), while Report Generator (what is used in Azure DevOps) reports 453/502 branches covered (~90.2%), This is usually not the case with lines coverage, though.

Could you maybe send me the logs and possibly the .coverage file for your pipelines to [email protected], so I can take a look?

In addition, I wonder why you have the sleep and the publish code coverage step in your pipeline. As far as I know, the DotNetCoreCLI task publishes coverage data automatically, so there is no need for the additional publish. In fact, it can change the coverage data as Azure DevOps might merge the two copies of the same coverage data into one dataset. If coverage is not automatically published by DotNetCoreCLI, the publish step is necessary, but the sleep step should probably after the publish step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants