【问题标题】:How to view the SonarQube full analysis report in the build summary in Azure DevOps?如何在 Azure DevOps 的构建摘要中查看 SonarQube 完整分析报告?
【发布时间】:2019-12-24 12:40:05
【问题描述】:

无法在 Azure DevOps 构建摘要中查看 SonarQube 结果。

我在 build.yml 中为我的 .netccore 和框架组件添加了代码覆盖率单元测试任务,但是当我尝试运行构建时,它仅显示单元测试任务的代码覆盖率。我不确定如何检查完整分析包括代码气味和覆盖的行数和质量门结果以及 azure devops 构建摘要本身。由于一些挑战,我无法登录到我的 SonarQube 机器,所以我想在构建摘要本身中查看结果。我在 build.yml 文件中添加了 SonarQube 任务来运行分析。

Build.yml:

name: $(date:yyyyMMdd)$(rev:.r)-$(SourceBranchName)

variables:
  BuildPlatform: 'Any CPU'
  BuildConfiguration: 'Release'
  Major: '0'
  Minor: '1'
  nugetversion: $(Major).$(Minor).$(Build.BuildId)
steps:
- task: DotNetCoreInstaller@0
  displayName: 'Use .NET Core SDK Tool Installer'
  inputs:
    version: 2.2.100
#Restore nuget for Test123
- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    vstsFeed: 'Test'

- task: SonarSource.sonarqube.15B84CA1-B62F-4A2A-A403-89B77A063157.SonarQubePrepare@4
  displayName: 'Prepare analysis on SonarQube'
  inputs:
    SonarQube: dksonarqubep01

    projectKey: 'TestKey'

    projectName: 'Test123'

  continueOnError: true

#Build solution for Test123
- task: CopyFiles@2
  displayName: 'Copy Files to: $(build.artifactstagingdirectory)/deployment'
  inputs:
    SourceFolder: deployment

    Contents: '**\*.*'

    TargetFolder: '$(build.artifactstagingdirectory)/deployment'

    CleanTargetFolder: true
- task: DotNetCoreCLI@2
  displayName: 'Build proj Test123'
  inputs:
    command: build
    projects: 'Test123.sln'
    arguments: '-c $(BuildConfiguration) --no-restore'

- task: DotNetCoreCLI@2
  displayName: 'dotnet test'
  inputs:
    command: test

    projects: |
     Test123.Tests/*.csproj

    arguments: '-c $(BuildConfiguration) --no-restore --no-build --collect:"Code coverage"'   

- task: DotNetCoreCLI@2
  displayName: 'dotnet publish'
  inputs:
    command: publish

    publishWebProjects: false

    projects: '**/*Test123.csproj'

    arguments: '-c $(BuildConfiguration) -o $(build.artifactstagingdirectory) --no-restore'


- task: PublishSymbols@2
  displayName: 'Publish symbols path'
  inputs:
    SearchPattern: '**\\bin\\**\\*.pdb'

    PublishSymbols: false

  continueOnError: true

- task: CopyFiles@2
  displayName: 'Copy deployment to: $(build.artifactstagingdirectory)'
  inputs:
    SourceFolder: deployment

    TargetFolder: '$(build.artifactstagingdirectory)\\env'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'

    ArtifactName: 'drop'

- task: SonarSource.sonarqube-9589-4B15-8491-8164AEB38055.SonarQubeAnalyze@4
  displayName: 'Run Code Analysis'
  continueOnError: true

- task: SonarSource.sonarqube-1ee4-45d3-b1b0-bf822d9095ef.SonarQubePublish@4
  displayName: 'Publish Quality Gate Result'
  continueOnError: true

我只能在单元测试的构建摘要中看到代码覆盖率百分比值,但我希望在构建摘要中看到完整的分析,而不是登录到 SonarQube 机器并查看结果。如果有任何任务需要,请帮助我在 build.yml 中执行任务以查看结果或以任何其他方式在 azure DevOps 中查看结果,而无需登录 SonarQube 机器。

【问题讨论】:

  • 用“完整分析”解释你的意思,因为SonarQube有很多选择。您可以使用 SonarQube API 创建自己的解决方案。
  • 这个问题有什么更新吗?你解决了这个问题吗?如果没有,请告诉我有关此问题的最新信息吗?
  • 我也有同样的问题。准备分析配置任务的第 3 版现已弃用,第 4 版似乎没有该选项。

标签: azure-devops sonarqube


【解决方案1】:

如何在 Azure DevOps 的构建摘要中查看 SonarQube 完整分析报告?

AFAIK,任务Prepare Analysis Configuration的版本3中有高级选项Include full analysis report in build summary,命名为Scanner for MSBuild - Begin Analysis: p>

用于将报告上传到构建摘要,结果将显示在构建摘要的底部。

或者,您可以尝试通过Logging Command(例如Write-Host "##vso[task.addattachment type=Distributedtask.Core.Summary;name=testsummaryname;]c:\testsummary.md")上传要构建的结果文件,它会显示在构建摘要的底部。

上传摘要标记并将其附加到当前时间线记录。这 摘要应添加到构建/发布摘要中且不可用 用于下载日志。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2020-12-19
    • 2023-03-13
    • 1970-01-01
    • 2018-06-21
    • 2020-08-21
    • 2018-07-07
    • 2020-08-19
    • 2011-01-10
    • 2019-07-04
    相关资源
    最近更新 更多