Quality Gate Failure After Renaming Projects in Azure DevOps

Hello. This is new topic based on previously created Quality Gate Failure After Renaming Projects in Azure DevOps
Description:
I encountered a Quality Gate failure with 0% coverage after renaming projects in my Azure DevOps environment. Here are the details:

  1. ALM Used: Azure DevOps
  2. CI System: Azure DevOps
  3. Languages of the Repository: C#

Issue:
The coverage is reported as zero, which likely caused the Quality Gate failure. Although I didn’t write any new code, I did rename the projects. Consequently, I had to remove and re-add them. Additionally, I fixed all the build files after renaming the projects.

Solution Structure Before Renaming:

  • Solution (abc)
    • ProjectA
    • ProjectB
    • ProjectC

Renamed Solution:

  • Solution (xyz)
    • ProjectX
    • ProjectY
    • ProjectZ

Logs with sonar.log.level “INFO” level should be enough? Or more verbose level should be used here? Thanks

Hey there.

Are you sure you’re still generating coverage reports after all the projects have moved around? What do the logs say about the import of coverage reports?

Hello. I didn’t find any suspicious in the logs. Coverage .coverage reports are exists in build agent temp folder and looks like a sonar scanner picked them off to analyze.

Here is logs-zero-coverage.txt where 0.0% coverage after renaming a project.
and logs-coverage.txt before renaming project.
logs-coverage.txt (60.0 KB)
logs-zero-coverage.txt (60.1 KB)

It’s weird that both logs seem to show files parsing successfully, but the latter (0% coverage) don’t show this line:

2024-06-03T13:30:52.0371181Z INFO: Coverage Report Statistics: 468 files, 468 main files, 468 main files with coverage, 0 test files, 0 project excluded files, 0 other language files.
2024-06-03T13:30:52.0371623Z INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=648ms

A few other things have changed that are unrelated to renaming of your projects.

For example it looks like you’ve moved to SonarCloudAnalyze@V2

Before:

2024-06-03T13:29:38.4301002Z ##[section]Starting: SonarCloud Run
2024-06-03T13:29:38.4371017Z ==============================================================================
2024-06-03T13:29:38.4371354Z Task         : Run Code Analysis
2024-06-03T13:29:38.4371431Z Description  : Run scanner and upload the results to the SonarCloud server.
2024-06-03T13:29:38.4371572Z Version      : 1.45.0
2024-06-03T13:29:38.4371639Z Author       : sonarsource
2024-06-03T13:29:38.4371758Z Help         : Version: 1.45.0. This task is not need

After:

2024-06-06T11:41:05.2822070Z ##[section]Starting: SonarCloud Run
2024-06-06T11:41:05.2831020Z ==============================================================================
2024-06-06T11:41:05.2831190Z Task         : Run Code Analysis
2024-06-06T11:41:05.2831286Z Description  : Run scanner and upload the results to the SonarCloud server.
2024-06-06T11:41:05.2831451Z Version      : 2.0.0
2024-06-06T11:41:05.2831514Z Author       : sonarsource
2024-06-06T11:41:05.2831658Z Help         : This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

Can you change your Prepare Analysis Configuration and Run Code Analysis tasks back to @V1 to see if it fixes the coverage issue? There would still be an issue for us to investigate, but at least we can be sure where the issue is.

For some reason when I switched to v1 I got an error. I didn’t faced with this issue before, when I run analysis with v1 task sonar tasks from feature branch…
logs-v1-sonartask-failed.txt (59.5 KB)

Hi. I had to switch to v2 to resolve this issue in previous message. Any updates?

Also here is our ADO build pipeline setup:

- task: SonarCloudPrepare@2
        displayName: 'SonarCloud Prepare for CI'
        condition: ne(variables['Build.Reason'], 'PullRequest')
        inputs:
          SonarCloud: '3E SonarCloud'
          Organization: 'org'
          ScannerMode: 'MSBuild'
          ProjectKey: 'projectKey'
          ProjectName: 'projectName'
          ExtraProperties: |
            sonar.branch.name=$(Build.SourceBranchName)

      - task: SonarCloudPrepare@2
        displayName: 'SonarCloud Prepare for PR'
        condition: eq(variables['Build.Reason'], 'PullRequest')
        inputs:
          SonarCloud: '3E SonarCloud'
          Organization: 'org'
          ScannerMode: 'MSBuild'
          ProjectKey: 'projectKey'
          ProjectName: 'projectName'

      - task: DotNetCoreCLI@2
        displayName: 'dotnet build'
        inputs:
          command: 'build'
          projects: '${{ parameters.buildSolution }}'
          arguments: '--configuration ${{ parameters.buildConfiguration }} --no-restore'

      - task: DotNetCoreCLI@2
        displayName: 'dotnet test'
        inputs:
          command: 'test'
          projects: '${{ parameters.buildSolution }}'
          arguments: '-c ${{ parameters.buildConfiguration }} --no-build --collect "Code Coverage" --settings ${{ parameters.coverageSettings }} -v normal'
          publishTestResults: true
      
      - task: SonarCloudAnalyze@2
        displayName: 'SonarCloud Run'
        inputs:
          jdkversion: 'JAVA_HOME_17_X64'
        continueOnError: true
          
      - task: SonarCloudPublish@2
        displayName: 'SonarCloud Publish'
        inputs:
          pollingTimeoutSec: '300'
        continueOnError: true

And codecoverage.runsettings file

<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<RunSettings>
	<DataCollectionRunSettings>
		<DataCollectors>
			<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
				<Configuration>
					<CodeCoverage>
						<ModulePaths>
							<Include>
								<ModulePath>.*\Genome.dll$</ModulePath>
								<ModulePath>.*\Genome.PSModule.dll$</ModulePath>
							</Include>
							<Exclude>
								<ModulePath>.*\Genome.Tests.dll$</ModulePath>
								<ModulePath>.*\Genome.PSModule.Tests.dll$</ModulePath>
								<ModulePath>.*\*coverlet*</ModulePath>
							</Exclude>
						</ModulePaths>
						<!-- We recommend you do not change the following values: -->
						<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
						<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
						<CollectFromChildProcesses>True</CollectFromChildProcesses>
						<CollectAspDotNet>False</CollectAspDotNet>
					</CodeCoverage>
				</Configuration>
			</DataCollector>
		</DataCollectors>
	</DataCollectionRunSettings>
</RunSettings>

Just to make sure, when you renamed your projects, did you also change your runsettings to reflect those new names?

Yes, of course, I renamed all references (runsettings as well) from the old name to the new name at one time and then run an analysis.

I was wondering why this logs do not appear after solution renaming?

I provided explicitly defined paths to .coveragexml and I still don’t see Coverage Report Statistics logs

- task: SonarCloudPrepare@2
        displayName: 'SonarCloud Prepare for CI'
        condition: ne(variables['Build.Reason'], 'PullRequest')
        inputs:
          SonarCloud: '3E SonarCloud'
          Organization: 'org'
          ScannerMode: 'MSBuild'
          ProjectKey: key'
          ProjectName: 'Genome'
          ExtraProperties: |
            sonar.branch.name=$(Build.SourceBranchName)
            sonar.cs.vscoveragexml.reportsPaths=$(Agent.TempDirectory)\**\*.coveragexml

Hi. Any thoughts? I’m kinda out of ideas how to resolve it

I tried to use another code coverage tool and updated SonarCloudPrepare@2 with

sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml"

also updated dotnet test task

- task: DotNetCoreCLI@2
  displayName: 'dotnet test'
  inputs:
    command: test
    projects: '$(Build.SourcesDirectory)/**/*Test*.csproj'
    arguments: '--verbosity n --configuration ${{ parameters.buildConfiguration }} --no-build --framework net6.0 /p:CollectCoverage=true /p:CoverletOutputFormat=opencover'
    publishTestResults: true
    testRunTitle: 'VS Tests with Code Coverage'
    nobuild: true

and now code coverage displays correctly

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