Azure Devops PR decoration

SonarQube Enterprise Edition Version 8.1 (build 31237)
SonarC# - Code Analyzer for C# 8.2 (build 14119)

What I want to achieve:
PR decoration to work on Azure DevOps

What I tried:
Followed the documentation at https://docs.sonarqube.org/latest/analysis/pr-decoration/ for Azure Devops Server. Generally analysis works and PRs also get analysed seperately. While testing deliberate code smells did not get commented on even though analysis said there was one.

That aside the status policy SonarQube/quality gate is also not available which I would also like to have as a requirement before a PR can be merged. I typed it in myself as suggested by some blogs but it remains a clock like icon which blocks PRs from being merged but not because the gate failed or passed.

If I also read correctly the following properties get set automatically?
sonar.pullrequest.key
sonar.pullrequest.branch
sonar.pullrequest.base

Thanks in advance!

Hello @niels.willems,
Can you have a look at How to block the merge of Pull Requests when SonarQube Quality Gate is failed, with Azure DevOps and let us know if it helps.
If that’s something else you want to achieve (or something else that does not work) can you clarify what ?
Regards,

Hello @OlivierK , thanks for the reply!

Unfortunately this Quality Gate status does not exist for me. Be it that the gate passes or fails it doesn’t block the PR. What currently happens is that publishing the Quality Gate works fine to SQ. However the build step does not fail (preferably that doesn’t fail the build as build, tests, publishes etc won’t fail due to a code smell).

The flow I am trying to achieve is:

  1. Create PR
  2. Build is triggered (which includes analysis + publishing quality gate result)
  3. Build succeeds however the status policy (which is nowhere to be found at the moment) would fail, if the code doesn’t meet the SQ requirements, blocking the PR.
  4. Code smells etc are added to the PR automatically so there is no need to always go check in SQ what is up.

At the moment what happens is:

  1. Create PR
  2. Build, tests, analysis, publishing quality gate results succeeds
  3. SQ is updated with the PR + analysis but no feedback is given to Azure Devops meaning no Status Policy that failed and no PR decoration.

What is set up is:

  • Administration -> PR decoration -> configuration ( PAT with read & write)
  • Project -> General Settings -> PR decoration -> Configuration name (the one created in the Administratin part of SQ)
  • Build pipeline which analyses the branch and pushes the results ( Prepare Analysis, Run Analysis and Publish Quality Gate Result from extension https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube )

Hello @niels.willems,
From your description of the problem I have the impression that the integration between Azure DevOps and SonarQube does not work as expected (wrong PAT, PAT with insufficient permissions in AzDo, …)
To understand the root cause of the integration failure you may want to:

  • Activate DEBUG logs in SonarQube (Administration --> System, then change Log Level from INFO to DEBUG)
  • Run your build with PR decoration again
  • Grab the Compute Engine logs (Administration --> System, then Download Logs --> Compute Engine)

Hopefully you’ll see there a WARNING or ERROR log that will explain why PR decoration does not happen.

Don’t forget to then reset you logs level back to INFO.

Regards,

Hello again @OlivierK … thanks for the input… I checked the logs and nothing of Azure DevOps seems to be mentioned… however there are some errors regarding some slack integration that fails, however for this particular project nothing for slack is configured as there should be no slack integration. Perhaps that causes the rest of the flow to not work either as the process probably stops? Will investigate further.

It could well be that a slack integration failure aborts the last steps of the compute engine background task.
You should try the same PR decoration after removal of the slack integration (a plugin I guess) to verify if it’s not the culprit, and safely proceed with the troubleshooting if it’s not.
Regards, Olivier

1 Like

Hello @OlivierK seems it was this Slack plugin causing the issue… uninstalled it now and everything works fine. Thanks for the help!