Example of c# Azure Devops pipeline that suppress rules

  • SonarQube version sonarqube-9.6.1.59531 - via Azure Devops pipelines.

Trying to suppress rules in c# using MSBuild scannerMode.

I don’t have access to the UI on the SonarQube Virtual Machine so cannot suppress in UI.

Suppress in azure-pipelines.yml
I have tried adding the suppression the SonarQubePrepare task, but this seems to have no effect.

  - task: SonarQubePrepare@5
    inputs:
      SonarQube: 'SonarQube Service Connection'
      scannerMode: 'MSBuild'
      configMode: 'manual'
      projectKey: ${{ parameters.projectKey }}
      projectName: ${{ parameters.projectName }}
      sources: ${{ parameters.sources }}
      extraProperties: |
        sonar.issue.ignore.multicriteria=e1,e2,e3,all
        sonar.issue.ignore.multicriteria.e1.ruleKey=csharpsquid:S4457
        sonar.issue.ignore.multicriteria.e1.resourceKey=**/*
        sonar.issue.ignore.multicriteria.e2.ruleKey=roslyn:CA2254
        sonar.issue.ignore.multicriteria.e2.resourceKey=**/*
        sonar.issue.ignore.multicriteria.e3.ruleKey=external_roslyn:CA2254
        sonar.issue.ignore.multicriteria.e3.resourceKey=**/*
        sonar.issue.ignore.multicriteria.all.ruleKey=*
        sonar.issue.ignore.multicriteria.all.resourceKey=**/*

Using sonar-project.properties
I have tried using sonar-project.properties but the MSBuild scanner rejects that file.

Using SonarQubeSetting Include=
I tried renaming the sonar-project.properties and including it via the SonarQubeSetting, but that didn’t work either.

	<ItemGroup>
		<SonarQubeSetting Include="CustomerPlanning.sonar-project.properties">
			<Value>**/*.cs</Value>
		</SonarQubeSetting>
	</ItemGroup>

Can you please provide a working example of the suppressions for the SonarQubePrepare task? All the support issues I have read say to use the UI, but that is not an option for me.

Tried as well in the csproj file:

<ItemGroup>
    <SonarQubeSetting Include="sonar.issue.ignore.multicriteria">
      <Value>c1</Value>
    </SonarQubeSetting>
    <SonarQubeSetting Include="sonar.issue.ignore.multicriteria.c1.ruleKey">
      <Value>csharpsquid:S3903</Value>
    </SonarQubeSetting>
    <SonarQubeSetting Include="sonar.issue.ignore.multicriteria.c1.resourceKey">
      <Value>**/*.cs</Value>
    </SonarQubeSetting>
  </ItemGroup>

Got a warning in the UI:

Specifying issue exclusions at module level is not supported anymore. Configure the property ‘sonar.issue.ignore.multicriteria’ and any other issue exclusions at project level.

@gaui could you share the verbose logs for the end step please?

To get this in Azure DevOps you should add the sonar.verbose to the Prepare step e.g.:

- task: SonarQubePrepare@5
    inputs:

      extraProperties: |
        sonar.verbose=true

Also, just to be clear on what you are trying to achieve:

  • you are trying to disable some rules completely without using the UI
  • some of the rules are Sonar C# analysis rules
  • some are Microsoft analysis rules

Is that correct?

Got it to work by changing the prefix of the exclusions.

sonar.issue.ignore.multicriteria=e1,e2,e3,all

sonar.issue.ignore.multicriteria=c1,c2,c3

Also Roslyn rules are supposed in C# using SuppressMessage.

1 Like

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