【问题标题】:SonarQube Analysing a specific FileSonarQube 分析特定文件
【发布时间】:2021-05-13 15:47:50
【问题描述】:

我正在尝试使用 sonarqube 分析我想每天运行的 azure devops git 存储库中的特定文件 (filename.ts)。

到目前为止我已经建立:

  1. A sonarqube project and generated project token in our sonarqube saas.
    
  2. Created a CD release pipeline in Azure DevOps including the predefined sonarqube tasks:
    
        *    prepare analysis on sonarqube (unclear to me how I configure this)
        *    run code analysis (looks as if this doesn't require configuration)
        *    publish quality gate (same belief here that it doesn't require configuration)
    
  3. Identified the repository where the file exists in the azure repo. 
    
  4. I have also discovered the artifact name that the repo's CI pipeline generates.
    
  5. Found a preconfigured sonarqube service connection in Azure DevOps.
    

我现在摸不着头脑的是确定以下几点:

a.  How to tell my CD pipeline where the file is in the azure repo. Should I point it to the file in the Repo? Or should i take it from the CI artifact?

b.  Would the sonarqube project require further configuration so to see the file?

我觉得这个谜题还有很多部分。谁能指出我正确的道路,请包括我可能没有想到的任何其他内容?

【问题讨论】:

    标签: typescript azure-devops continuous-integration sonarqube continuous-deployment


    【解决方案1】:

    首先您需要检查预配置的 sonarqube 服务连接是否指向您的 sonarqube 主机。

    在azure devops中转到Project settings-->Service connections-->选择预配置的sonarqube service connection-->单击Edit-->检查Server Url是否指向您的声纳主机url。

    如果预配置的 sonarqube 服务连接指向不同的 sonarqube 主机。您需要为您的 sonarqube 主机创建一个新的 sonarqube 服务连接。

    分析特定文件:

    您可以将sonar.inclusions 属性设置为仅分析特定文件。见下图。请查看document Narrowing the Focus 了解更多信息。

    您可以在发布管道的准备分析配置任务的Additional Properties 字段中配置sonar.inclusions 属性。

    或者您也可以在 SonarQube 项目 UI 中设置 sonar.inclusions 属性。

    要使用排除项仅分析 sonar.sources 中指定的文件子集,请转到项目设置 > 常规设置 > 分析范围 > 文件。

    • 源文件包含
    • 测试文件包含

    【讨论】:

    • 谢谢@Levi,我关注了你的详细回复。我确实遇到了一个缺失的组件:“错误:找不到模块'typescript'”。这是我可以在 Azure CD 发布管道中的单独步骤中安装的东西吗?
    • 你好@Levi,我通过添加一个安装打字稿npm的任务解决了这个错误。这是一个简单的 bash 脚本“npm install typescript”。感谢您的帮助,我会将您标记为已接受的答案。
    猜你喜欢
    • 1970-01-01
    • 2015-03-20
    • 2017-03-22
    • 1970-01-01
    • 2016-01-26
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多