Branch display name in SonarCloud using SonarC Scanner

I am using SonarC-Scanner to do a analysis on my Objective-C code in Azure DevOps and upload results to SonarCloud.
We also have a Android project where we are scanning and uploading results to SonarCloud.

What I recently noticed was that the scan for our Android project requires no additional work setting parameters when it comes to PR’ids and branch names in SonarCloud, but in our Objective-C project we had to set the sonar.pullrequest.key parameter so that we would see the PR branch before merge’ing to master ( short lived branch ).

In our Android Project we see the description for the short lived branches as
[PR_id] - [PR_description]

But the default for the Objective-C project the naming is
[PR_id] - [PR_GIT path for example /refs/heads/fix-heading]

Is it the right way to set these parameters manually or is there something I am doing wrong when invoking the Sonar Scanner ?

This is my Sonar task in Azure DevOps:

  • bash: |
    (Build.SourcesDirectory)/sonar-scanner- \<sonar host> \ -Dsonar.login=<sonar login> \ -Dsonar.projectKey=<project key> \
    -Dsonar.sources=(Build.SourcesDirectory) \ -Dsonar.c.file.suffixes=- \ -Dsonar.cpp.file.suffixes=- \ -Dsonar.objc.file.suffixes=.h,.m \ -Dsonar.organization=<org name> \ -Dsonar.projectVersion=(Build.MarketVersion)_(Build.BuildNumber) \ -Dsonar.pullrequest.key=(System.PullRequest.PullRequestId)
    displayName: SonarCloud-Run-Scanner

Also, we set the personal access token in SonarCloud for Integration with Azure DevOps Services. That also works out of the box for our Android project but we do not get the update for the Objective-C project, so it seems that some properties are correctly configured.

Hi @ivarorn,

Did you try at some point to use our Azure DevOps extension ? So you will just have to configure your build wrapper, and everything else will be done for you, such as the proper pull request key / id settings, …


hi @mickaelcaro

Yes I originally tried that but was not able to get that one working with my objective-c code base (sonar-c scanner ). Worked fine with my swift demo project.

Ran into issues with java paths and permissions in azure devops.

Are you suggesting that I run the build wrapper and then use the sonar scan extensions and publish extensions ? Is there any way of running sonarc scanner without publishing the results to sonarcloud ?

Hi @ivarorn

In fact the Build Wrapper shall be used just like the Scanner CLI itself in terms of integration with the extension : just wrap the build command between the Prepare Analysis Configuration and Run Code Analysis, and you should be good to go.

You can definitely run it alone, as a powershell or bash task, like you did with the Scanner above (you have some samples available here and here