首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用用于Azure DevOps Server 2020的DevOps任务,如何禁止所有静态代码分析,但上载覆盖率报告?

使用用于Azure DevOps Server 2020的DevOps任务,如何禁止所有静态代码分析,但上载覆盖率报告?
EN

Stack Overflow用户
提问于 2021-03-12 05:29:38
回答 1查看 574关注 0票数 0

我有一个建筑:

report

  • Includes
  • 运行dotCover来生成覆盖率,并准备和分析任务,以便将覆盖报告上传到SQ.

该代码已经过时,存在大量静态代码分析问题。我决定通过在队列时间设置SonarQubeExclude = true构建变量来全局地抑制SQ静态代码分析。

问题是SQ分析任务失败了:

代码语言:javascript
运行
复制
##[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分析任务,并且不会上载覆盖报告。

我知道修复它的一种方法是创建一个没有静态代码分析规则的Quality,并配置相应的SQ项目来使用它。

我能让它工作而不触及服务器端的配置吗?我不明白为什么SonarQubeExclude最终未能完成SQ分析任务。

大致相同的YAML模板被许多构建重用--一些关闭SQ任务,一些打开它们(条件YAML),但我不能做的是将SQ准备任务放在中间--所以它要么被关闭,要么打开,然后在所有构建之前运行。

SQ的准备任务:

代码语言:javascript
运行
复制
  - 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分析任务:

代码语言:javascript
运行
复制
      - task: SonarQubeAnalyze@4
        displayName: "Run SQ Analysis"

为了清楚起见,我省略了条件。

所有的构建都发生在这两个任务之间。

是否可以完全禁止静态代码分析,只上传覆盖率报告而不更改服务器端设置?

EN

回答 1

Stack Overflow用户

发布于 2021-03-15 10:41:00

我不明白为什么SonarQubeExclude在最后没有完成SQ分析任务。

设置该属性可以有效地告诉扫描仪,就像MSBuild项目不存在一样,因此不会报告任何问题或覆盖率。如果您已经排除了所有的MSBuild项目,那么扫描仪会抱怨没有什么可上传的。

我可以让它工作而不触及SQ服务器端的配置吗?

没有一个支持的方法来做这件事,没有。支持的选项是上传问题和覆盖,但不能忽略问题,或者像您描述的那样创建一个没有活动规则的高质量配置文件。

关于支持对旧代码进行分析的论点是检测安全漏洞,因此至少您知道这些漏洞。创建一个只包含安全规则的有限的质量配置文件,并使用它,这可能是值得的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66594663

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档