DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. Analyze Your OS Code For Free With Azure DevOps Pipelines and SonarCloud

Analyze Your OS Code For Free With Azure DevOps Pipelines and SonarCloud

Tatke a look at how you can have the stability of your code checked for free using previously-established Azure pipelines and SonarCloud.

Ricci Gian Maria user avatar by
Ricci Gian Maria
·
Oct. 15, 18 · Tutorial
Like (2)
Save
Tweet
Share
6.01K Views

Join the DZone community and get the full member experience.

Join For Free

in previous posts, i've shown how easy it is to create a yaml definition to create a build definition to build your github open source project in azure devops, without the need to spend any money or installing anything on your server.

once you create a default build that compiles and run tests, it would be super nice to create a free account in sonarcloud to have your project code to be analyzed automatically from the azure pipeline you've just created. i've already blogged on how to setup sonarcloud analysis for os project with vsts build and the very same technique can be used in yaml build.

once you have free yaml azure devops pipeline, it makes sense to enable analysis with sonarcloud.

first of all, you need to register to sonarcloud, create a project, set up a key, and create a token to access the account. once everything is in place you can simply modify the yaml build to perform the analysis.

figure 1: task to start sonarcloud analysis.

the above task definition can be obtained simply by creating a build with a standard graphical editor, then press the yaml build to have the ui generate the yaml for the task.

actually yaml build does not have an editor, but it is super easy to just create a fake build with standard editor, drop a task into the definition, populate properties then let the ui to generate yaml that can be copied into the definition.

once the analysis task is in place, you can simply place the "run code analysis task" after build and test tasks. the full code of the build is the following.

# .net desktop
# build and run tests for .net desktop or windows classic desktop solutions.
# add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net

pool:
  vmimage: 'vs2017-win2016'

trigger:
- master
- develop
- release/*
- hotfix/*
- feature/*

variables:
  solution: 'migration/migrationplayground.sln'
  buildplatform: 'any cpu'
  buildconfiguration: 'release'

steps:

- task: gitversion@1
  displayname: gitversion 
  inputs:
    buildnameprefix: 'migrationci'

- task: sonarsource.sonarqube.15b84ca1-b62f-4a2a-a403-89b77a063157.sonarqubeprepare@4
  displayname: 'prepare analysis on sonarqube'
  inputs:
    sonarqube: 'sonarcloud'
    projectkey: xxxxxxxxxxxxxxxxxxx
    projectname: migrationplayground
    projectversion: '$(assemblyversion)'
    extraproperties: |
     sonar.organization=alkampfergit-github
     sonar.branch.name=$(build.sourcebranchname)

- task: nugettoolinstaller@0

- task: nugetcommand@2
  inputs:
    restoresolution: '$(solution)'

- task: vsbuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildplatform)'
    configuration: '$(buildconfiguration)'

- task: vstest@2
  inputs:
    platform: '$(buildplatform)'
    configuration: '$(buildconfiguration)'

- task: sonarsource.sonarqube.6d01813a-9589-4b15-8491-8164aeb38055.sonarqubeanalyze@4
  displayname: 'run code analysis'




once you changed the build just push the code and let the build run. you should check if the build completes without error, then verify if the analysis is present in the sonarcloud dashboard.

a couple of suggestion are useful at this point: first of all, you can encounter problems with endpoint authorization, if you have such problem, check this link . another issue is that you should analyze the master branch for the first analysis for sonarcloud to work properly. until you analyze master branch, no analysis will be shown to sonarcloud.

figure 2: analysis in sonarcloud after a successful master build


if everything is green you should start seeing analysis data on sonarcloud ui.

figure 3: sonarcloud badge added to readme.md of the project.


as you can see, just a few lines of yaml and i have my code automatically analyzed in sonarcloud, thanks to azure devops pipelines that already have tasks related to sonarcube integration.

a nice finishing touch is to grab the badge link for the sonarcloud analysis and add it to your github readme.md.


azure Pipeline (software) DevOps Build (game engine) Analyze (imaging software) Task (computing)

Published at DZone with permission of Ricci Gian Maria, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • OpenID Connect Flows
  • Choosing the Best Cloud Provider for Hosting DevOps Tools
  • Utilize OpenAI API to Extract Information From PDF Files
  • The Top 3 Challenges Facing Engineering Leaders Today—And How to Overcome Them

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: