How to add pull request decoration in Azure DevOps with SonarQube Cloud (SonarCloud) for idiots

SonarCloud – brilliant at analyzing code, absolutely terrible at explaining how to set it up. Seriously, how can one tool be so effective at finding bugs yet make its documentation feel like deciphering ancient hieroglyphics while blindfolded?

Today we’re tackling how to add pull request decoration in Azure DevOps with SonarQube Cloud (SonarCloud), written by someone who spent way too many hours banging their head against this particular wall. This guide builds on Marc Rufer’s excellent work on [HOWTO] Integrate SonarCloud analysis in an Azure DevOps YAML pipeline – the man who graciously helped rescue me from my own confusion.

Project Structure

Here’s what we’re working with:

Step 1: Write the Pipelines

I recommend following Marc’s guide for the details, but here’s my battle-tested configuration that actually works:

solution-quality.yml

jobs-build-quality.yml

jobs-build-python-functions.yml

Step 2: Configure Branch Policies (The Moment of Truth)

Once you’ve set up your pipeline with the right permissions – again, check out Marc’s post for the detailed setup requirements -> head over to the branch policies for your main development branch. Mine is called ‘dev’, but yours might be ‘development’ or whatever naming convention you use.

You’ll want to add the SonarCloud pipeline to the build validation.

Step 3: Configure SonarQube Cloud (SonarCloud) Integration (The Critical Part Everyone Skips)

Once you’ve added the SonarQube Cloud (SonarCloud) pipeline to your build validation, head over to SonarCloud.io and navigate to your project page.

Go to Administration → Pull Requests and add a new Personal Access Token (PAT).
This is where the magic happens – SonarCloud needs this token to communicate back to Azure DevOps and update your pull request status checks.

Important: Use a technical user or service account in Azure DevOps instead of your personal PAT. This prevents the integration from breaking when people leave the team or change passwords. Create a dedicated service account specifically for SonarCloud integration – your future self will thank you when you’re not troubleshooting broken integrations at 2 AM.

This step is crucial – without the proper PAT configuration, SonarCloud can analyze your code but can’t send the results back to Azure DevOps. You’ll see analysis results in SonarCloud but no status checks in your pull requests, which defeats the whole purpose.

Step 4: Test Your Setup (The Moment of Truth)

Create a new pull request to your dev branch. Once the SonarCloud step finishes successfully, you should see comments appearing in your PR with code quality feedback.

But wait, there’s more! (And by more, I mean potential disasters)
You might encounter this delightful error that had me questioning my life choices:

If this happens to you (and it probably will, because apparently I’m not the only one who struggles with this), here’s how to fix it:

First: Check Your Repository Binding

The issue is likely that SonarCloud isn’t properly connected to your Azure DevOps repo.

Check SonarCloud repository binding:

  • Go to SonarCloud → Your project → Administration → Integration
  • Verify the “Repository” field points to the correct Azure DevOps repo
  • Format should be: {organization}/{project}/{repository}

If Nothing Shows Up: Your Organization Binding is Broken

This was my problem – the organization-level connection was toast.

  • Go to SonarCloud → Organizations → Administration → Organization Binding
  • If the PAT shows as invalid, there’s your smoking gun
  • Add a new PAT – I used the service account’s PAT
  • Make sure the service account has proper permissions in both SonarCloud and Azure DevOps
  • Once valid, you should see projects appear in the repository binding section

Final Test: Create Chaos

Create a new PR with intentionally bad code – add a ridiculously smelly class to watch SonarCloud lose its mind.
There’s nothing quite like seeing SonarCloud tear apart your deliberately terrible code to confirm everything is working properly.

Here’s mine :
SonarCloudPrTestService.cs

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top