【发布时间】:2026-01-20 17:55:01
【问题描述】:
我有一个构建:
- 运行 dotCover 以生成覆盖率报告
- 包括 SQ 准备和分析任务以将覆盖率报告上传到 SQ。
代码陈旧,存在大量静态代码分析问题。我决定通过在队列时间设置 SonarQubeExclude = true 构建变量来全局抑制 SQ 静态代码分析。
问题是SQ Analyze任务失败:
##[section]Starting: Run SQ Analysis
==============================================================================
Task : Run Code Analysis
Description : Run scanner and upload the results to the SonarQube server.
Version : 4.18.0
Author : sonarsource
Help : Version: 4.18.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.
[More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================
[command]...
SonarScanner for MSBuild 5.1
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
23:11:35.03 The exclude flag has been set so the project will not be analyzed. Project file: SomeProject.csproj
...
23:11:35.03 The exclude flag has been set so the project will not be analyzed. Project file: SomeProject2.csproj
##[error]23:11:35.046 No analysable projects were found. SonarQube analysis will not be performed. Check the build summary report for details.
23:11:35.046 No analysable projects were found. SonarQube analysis will not be performed. Check the build summary report for details.
23:11:35.03 The exclude flag has been set so the project will not be analyzed. Project file: SomeProject3.csproj
...
23:11:35.046 The exclude flag has been set so the project will not be analyzed. Project file: SomeProject4.csproj
23:11:35.046 Generation of the sonar-properties file failed. Unable to complete the analysis.
##[error]23:11:35.046 Post-processing failed. Exit code: 1
23:11:35.046 Post-processing failed. Exit code: 1
##[error]The process '...
##[section]Finishing: Run SQ Analysis
这会中止 SQ 分析任务,并且不会上传任何覆盖率报告。
我知道修复它的一种方法是创建一个没有静态代码分析规则的质量门,并配置相应的 SQ 项目以使用它。
我可以在不触及 SQ 服务器端配置的情况下使其工作吗?我不明白为什么 SonarQubeExclude 最后失败了 SQ 分析任务。
或多或少相同的 YAML 模板被许多构建重用了一些关闭 SQ 任务,一些打开它们(有条件的 YAML),但我不能做的是把 SQ Prepare 任务放在中间 - 所以要么它被打开在所有构建之前关闭或打开并运行。
SQ Prepare 任务:
- task: SonarQubePrepare@4
displayName: Prepare CI SQ Analysis
inputs:
SonarQube: SonarQube
scannerMode: MSBuild
projectKey: $(SonarQubeProjectKey)
projectName: $(SonarQubeProjectName)
projectVersion: $(SonarQubeProjectVersion)
extraProperties: |
sonar.cs.vscoveragexml.reportsPaths=$(Common.TestResultsDirectory)\vstest-coverage\*.xml
sonar.cs.dotcover.reportsPaths=$(Common.TestResultsDirectory)\coverage\*.CoverageResult.html
sonar.cs.opencover.reportsPaths=$(Common.TestResultsDirectory)\coverage\*.CoverageResult.xml
sonar.cs.nunit.reportsPaths=$(Common.TestResultsDirectory)\tests\*.TestResult.xml
sonar.inclusions=**/*.cs
sonar.branch.name=$(SonarQubeSourceBranch)
sonar.scm.disabled=true
SQ 分析任务:
- task: SonarQubeAnalyze@4
displayName: "Run SQ Analysis"
为了清楚起见,我省略了条件。
所有构建都发生在这两个任务之间。
是否可以完全禁止静态代码分析,只上传覆盖率报告而不更改服务器端设置?
【问题讨论】:
标签: c# azure-devops msbuild sonarqube sonarqube-scan