Use pull request decoration in Azure DevOps with SonarCloud

Some time ago I wrote about how to fail your Azure Pipeline, if your SonarQube quality gate fails. I often get the request how you can do the same thing with SonarCloud. But it’s much better to use pull request decoration. This is really an awesome feature. You get the SonarQube Errors directly in the pull request and the quality gate is evaluated.

The configuration is a bit tricky and the options are pretty hard to find. And this only works in SonarCloud or with the SonarQube Developer Edition! I switched completely to SonarCloud – this is much more convenient.

I asume that you already have a build with the prepare, run and publish tasks configured. Note that there is a different extension for SonarCloud then for SonarQube. Add and configure the tasks accordingly and run the build with the analysis.

Now got to the project in SonarCloud. Go to “Generell Settings”, “Pull Requests”. Select VSTS and enter a Personal Access Token for Azure DevOps that SonarCloud uses to connect to Azure DevOps.

Now run the build again. If the analysis is complete got the the branch policy in your Azure Repo. If you now add a new Status Policy you will find in the drop down a policy called “SonarCloud/quality gate”. Select it and save the policy.

That’s it! Now create a pull request and enjoy the SonarCloud decoration. The Status Policy will fail the PR if the SonarCloud Quality Gate fails.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s