0
votes

Not able to view SonarQube results in the Azure DevOps build summary.

I have added code coverage unit test task in the build.yml for my .netccore and framework component but when I try running the build its showing the code coverage for unit test tasks only.I am not sure how to check the full analysis including code smells and how many lines covered and quality gate result as well in the azure devops build summary itself.Due to some challenges I couldn't able to loginto my SonarQube machine so I wanted to view the results in the build summary itself.I have added the SonarQube task to run analysis in the build.yml file.

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

I could see only code coverage percentage value in the build summary for unit tests but I would like to see the complete analysis in the build summary rather than login to SonarQube machine and see the results.Kindly help me if there any task need to task in the build.yml to see the results or any other way to see the results in the azure DevOps without login to SonarQube machine.

1
Explain what you mean with "complete analysis", because SonarQube has a lot of options. You could create your own solution by using the SonarQube API. - Jeroen Heier
Any update for this issue? Have you resolved this issue? If not, would you please let me know the latest information about this issue? - Levi Lu-MSFT
I have the same question. Version 3 of the Prepare Analysis Configuration task is now depreciated and version 4 doesn't appear to have the option. - Marvin

1 Answers

0
votes

How to view the SonarQube full analysis report in the build summary in Azure DevOps?

AFAIK, there is the advanced option Include full analysis report in build summary in the version 3 of the task Prepare Analysis Configuration, which named Scanner for MSBuild - Begin Analysis:

enter image description here

It is used to upload the report to build summary and the result will be show in the bottom of build summary.

Alternatively, you can try upload the result files to build through Logging Command (e.g. Write-Host "##vso[task.addattachment type=Distributedtask.Core.Summary;name=testsummaryname;]c:\testsummary.md") and it will show in the bottom of build summary.

Upload and attach summary markdown to current timeline record. This summary shall be added to the build/release summary and not available for download with logs.

Hope this helps.