Unable to use merge request decoration

Hello ,

I’m trying to use sonarqube (developper edition in evaluation) tu use merge request decoration with gitlab.
I cannot have any results.

i use

  • sonarqube
  • sonar-scanner (Java 11.0.3 AdoptOpenJDK (64-bit) - Linux 4.19.62-mod-std-ipv6-64-rescue amd64)
  • Gitlab CE 13.6.1

I configure sonar as describe in https://docs.sonarqube.org/latest/analysis/pr-decoration/
in /admin/settings?category=almintegration

  • I define my GitLab URL : https://gitlab.mycompagny.com/api/v4/
  • I set my personal key with api scope permission
  • Merge Request Decoration & Import repositories from your ALM are displayed as enabled.
  • i set my gitlab project id in my sonar project sonfiguration

I use sonar-scanner using with cli in a gitlab-ci job .that is trigger on each commits.

Can you help me to use merge request decoration?

Hi, is the merge request analyzed on SonarQube? Can you access it? When you are browsing the MR page, Is there any warning displayed at the top-right of the page?

Thanks Pierre (are you french?)

There is nothing in sonar MR page
I maybe need to define sonar.pullrequest.xx variable. ? I will try this


Can you please share with us your .gitlab-ci.yml file?

I just add sonar.pullrequest.* variables.

Now i can see merge request in sonarqube but there is no decoration un gitlab.

Here my .gitlab-ci.yml

  - Quality
  stage: Quality
    - /opt/sonar-scanner/bin/sonar-scanner -Dsonar.projectKey=$SONAR_PROJECT -Dsonar.qualitygate.wait=true -Dsonar.sources=$SONAR_SOURCES -Dsonar.pullrequest.key=$CI_MERGE_REQUEST_ID -Dsonar.pullrequest.base=$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME -Dsonar.pullrequest.branch=$CI_MERGE_REQUEST_LABELS
    - merge_requests

You don’t need those, the scanner detects them, according to our documentation for Gitlab CI/CD pipeline.

The most important piece is

    - merge_requests

That trigger merge pipeline, that will contain the env variable that can be detected. Now that you have your MR analyzed, any warning on the MR on SQ?

Ok, i deleted -Dsonar.xxx it work without this indeed

I got a warning on sonar :

Could not find ref ‘master’ in refs/heads, refs/remotes/upstream or refs/remotes/origin. You may see unexpected issues and changes. Please make sure to fetch this ref before pull request analysis.

I juste retry a new merge request and now it seems to be OK !

I cannot understant what happend but it seems to be good now :slight_smile:

This error happens when you stay on the default clone strategy, a shallow clone. This is why we advise using


as env variable, to ensure the scanner will find others branches in the local git repo after the clone.

Thanks :+1:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.