Azure DevOps

Learn how to integrate a DevPrime microservice into sonar cloud using the Azure DevOps pipeline.

The Sonar Cloud provides a tool to assist in the analysis of technical debt in software projects also allowing to find possible bugs and vulnerabilities acting as a support platform in improving the quality of projects.

Sonar can be integrated with services such as Azure DevOps, Github, Gitlab, Bitbucket, and many others allowing you to upgrade to each version generated.

Items needed in your environment

**Creating and obtaining project credentials
The first step is to create a new project and get the SONAR_TOKEN

DevPrime Sonar Cloud

Creating Azure Pipeline yaml
Create a new file in the project folder with the name “azure-pipelines.yml”
and add the contents of the yaml.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
##########################################################################
# Create an environment variable "SONAR_CLOUD_TOKEN" to put the token
##########################################################################

trigger:
- main

pool:
  vmImage: ubuntu-latest

variables:
  buildConfiguration: 'Release'

steps:

- task: UseDotNet@2
  displayName: 'Install .NET 6.x SDK'
  inputs:
    packageType: 'sdk'
    version: '6.x'
    includePreviewVersions: true


- task: CmdLine@2
  displayName: 'Starting Sonar Scanner'
  inputs:
    script: |
      echo Installing Sonar Scanner tool
      dotnet tool install --global dotnet-sonarscanner     
      echo Starting ...
      dotnet sonarscanner begin /o:devprimelabs /k:stack-startup /d:sonar.host.url=https://sonarcloud.io  /d:sonar.login=$(SONAR_CLOUD_TOKEN)

- script: dotnet build --configuration $(buildConfiguration)
  displayName: 'dotnet build $(buildConfiguration)'


- task: CmdLine@2
  displayName: 'Collect Sonar results and Publish'
  inputs:
    script: |
      echo Collect Sonar results and Publish
      dotnet-sonarscanner end /d:sonar.login=$(SONAR_CLOUD_TOKEN)

Commit

1
2
3
git add . 
git commit -am "sonarcloud"
git push

Creating a New Pipeline in Azure DevOps
Follow the steps in the Azure DevOps portal to create a new Pipeline using the file “azure-pipelines.yml” exists.

  • Pipelines
  • New pipeline
  • Azure Repos Git
  • Existing Azure Pipelines YAML file

Find and click the “Variables” button to create the new “SONAR_CLOUD_TOKEN” and add the token value obtained in the Sonar Cloud.

DevPrime Sonar Cloud

Start the Pipeline you just created. At the end the result will be published in Sonar Cloud.

Viewing in the Sonar Cloud portal
With each Build in Azure DevOps the result is published to sonar cloud so you can keep up with the technical evolution of development.

DevPrime Sonar Cloud

Last modified March 14, 2022 (134cd69)