SonarCloud Guality Gate in pull request in Azure Devops

  • ALM used Azure DevOps
  • CI system used Azure DevOps
  • Languages of the repository C#, angular
  • Private project
  • No errors

I have organization with multiple projects in Azure DevOps. I was able to implement SonarCloud scan into my PR validation pipelines, that runs as part of pull requests for each project. But I have problem with implementing quality gate result into PR. Wierd is that in some PRs it works, but most dont.

This repos was originaly in Bitbucket and now its in ADO. After this migration, I created new organization. In pipelins i changed only service connection, organiuzation, project key and project name.

Here are pipeline steps in pipeline yaml:

for angular
- checkout: self
fetchDepth: 0
# Prepare the SonarCloud analysis
- task: SonarCloudPrepare@2
inputs:
SonarCloud: ‘SonarCloud’
organization: ‘org’
scannerMode: ‘CLI’
configMode: ‘manual’
cliProjectKey: ‘portal’
cliSources: ‘.’
# Run the SonarCloud analysis
- task: SonarCloudAnalyze@2

     # Publish the SonarCloud analysis results
     - task: SonarCloudPublish@2
       inputs:
         pollingTimeoutSec: '300'

for .net
- checkout: self
fetchDepth: 0 # Disable shallow clone to fetch all history for SonarCloud analysis
- task: SonarCloudPrepare@2
inputs:
SonarCloud: ‘Sonar Cloud’ # Ensure this is the name of your service connection for SonarCloud
organization: ‘choice’ # Your organization key in SonarCloud
scannerMode: ‘MSBuild’
projectKey: ‘api_project’ # Your project key in SonarCloud
projectName: ‘API’
- template: Stages/build-proc.yml
- task: SonarCloudAnalyze@2
- task: SonarCloudPublish@2
inputs:
pollingTimeoutSec: ‘300’

This part works. PR pipeline scan my code(main, or side branch, or pull request, depens on which branch i setup) I can see results in sonar cloud website as well in pipeline(extensions, quality gate)

Steps I did

  • runed test for main branch, as well as part of pull request.

  • in sonar cloud website in project Administration => Pull request => I set provider to Azure Devops Services, Inserted PAT token with read and write code, and status and enabled summary comments.

  • in branch settings I tryed to add guality gate. In some project i can see it in dropdown menu, in most of them I dont, If its there quality gate works.

  • I tryed to add it manualy but in that case PR guality gate is stuck with waiting status…

  • I checked background tasks in sonar but i cant see anything wierd there

Does someone have similar issue? Did I skipped some step? I will be greatfull for any advice.

Branch policy


PR

PR pipeline results

Hey there.

In projects where the PR Decoration isn’t working – can you check that your project is bound to the right project?

Hello Colin, thanks for reply.
I think that my project is bind correctly. Name of project is same as my repository. Here is screenshot.

I’ve sent you a private message

Hello all,

I don`t know if this problem was solved, and it is my first post. My problem is related with this, because I am stuck waiting the Sonar Cloud Quality Gate result.

Since a month ago, in our main repo, the clean as you code approach started failed, because the sonar quality gate result has not been published in our Azure DevOps PRs.

At that time we moved to an optional Status Check, because we read that Azure DevOps was presenting some stability problem. In meanwhile we tried to change the PAT, run with another service connection (one that is working for another project) but we are still stuck.

Reading the posts this one is the most recent. So do you have any other suggestion or checklist or validation that we could work on?

Thanks in advance.

Hey @klausk

We didn’t arrive at a conclusive answer (@Ondrej_Domsky stopped responding). I’d invite you to create a new post.

Hello, sorry for not updating thread.

In my case worked solution in style “have you tried to turn it of and on again” :slight_smile:

I simply runed my sonar cloud pipeline multiple times from main branch and in pull request. Like 1-2 times each and eventualy quality gate showed up. I applied this also for pipeline where I added quality gate and it stuck in waiting status with additional step. Here I also removed it and add it again. (remove, not only disable).

Not sure if this help your case.

Ondrej