# Sonar Badges in GitLab

**URL:** <https://community.sonarsource.com/t/sonar-badges-in-gitlab/54476>\
**Category:** SonarQube Server / Community Build\
**Tags:** badges, sonarqube\
**Created:** [December 7, 2021, 12:30pm UTC](https://community.sonarsource.com/t/sonar-badges-in-gitlab/54476 "2021-12-07T12:30:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jariwala](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jariwala](https://community.sonarsource.com/u/jariwala)\
**Post date:** [December 7, 2021, 12:30pm UTC](https://community.sonarsource.com/t/sonar-badges-in-gitlab/54476/1 "2021-12-07T12:30:05Z")

</div>

Hi,

We are using SonarQube 7.9.6. We would like to promote sonar analysis in CI tools like GitLab using Sonar project Badges.

We have followed steps to configure sonar project badges in GitLab and ensured that we are using token for secure communication between SonarQube and GitLab.

It is observed that we are not seeing sonar badges in GitLab as expected and getting results as below:

 ![Screenshot 2021-12-07 at 5.51.43 PM](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/8/7/874747f69e3586bec8e2b58c58f1af6f9fa596dd.png)

However, Badges are getting appeared only when you logged in to SonarQube in same browser.

 ![Screenshot 2021-12-07 at 5.55.07 PM](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/3/b/3beec295032536612459882163002f26b4df3068.png)

Please note that we have enabled enforced user authentication in SonarQube(Administration \> General Settings \> Security).  
The sonar project in question is public one.

Thanks,  
Vaibhav Jariwala

---

<div class="post-metadata">

**Author:** ![pierreguillot](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/pierreguillot/32/46022_2.png) [@pierreguillot](https://community.sonarsource.com/u/pierreguillot)\
**Post date:** [December 7, 2021, 12:52pm UTC](https://community.sonarsource.com/t/sonar-badges-in-gitlab/54476/2 "2021-12-07T12:52:09Z")

</div>

Hi, project badges don’t work with force authentication enabled in 7.9.6.

This has been improved with SonarQube 9.2 & [SONAR-13426](https://jira.sonarsource.com/browse/SONAR-13426). Starting with SonarQube 9.2, project badge links are generated with a dedicated token in the URL that allows access only to this badge.

---

<div class="post-metadata">

**Author:** ![jariwala](https://avatars.discourse-cdn.com/v4/letter/j/f475e1/32.png) [@jariwala](https://community.sonarsource.com/u/jariwala)\
**Post date:** [December 7, 2021, 1:27pm UTC](https://community.sonarsource.com/t/sonar-badges-in-gitlab/54476/3 "2021-12-07T13:27:15Z")

</div>

> [@pierreguillot](#):
>
> project badges don’t work with force authentication enabled in 7.9.6.

Thanks letting us know the feature incompatibility with SonarQube 7.9.6.

---

<div class="post-metadata">

**Author:** ![lfvjimisola](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/lfvjimisola/32/28401_2.png) [@lfvjimisola](https://community.sonarsource.com/u/lfvjimisola)\
**Post date:** [December 14, 2021, 11:07am UTC](https://community.sonarsource.com/t/sonar-badges-in-gitlab/54476/4 "2021-12-14T11:07:15Z")

</div>

Is there a way to configure Sonar badges on Group level in GitLab for it appear in all sub-projects?

I can easily be done with the normal badges (e.g. pipeline). See: [Badges · Project · User · Help · GitLab](https://git.lfv.se/help/user/project/badges#group-badges)

And by setting Link and Badge image URL as follows:

- **Link** , enter the following URL: `https://gitlab.com/%{project_path}/-/commits/%{default_branch}`
- **Badge image URL** , enter the following URL: `https://gitlab.com/%{project_path}/badges/%{default_branch}/pipeline.svg`

However, SonarQube badges use the format with project key and project token:

[https://sonarqube.somehost/api/project\_badges/measure?project=](https://sonarqube.somehost/api/project_badges/measure?project=)\<project key \>&metric=code\_smells&token=\<project token\>

Hence, it can’t be set at Group Level and using Placeholders on project level (available placerholders are %{project\_path}, %{project\_id}, %{default\_branch} and %{commit\_sha}). If one could set manual placeholder (as with environment variables) then it would work.

Another option is of course to use the Markdown version instead.

Any suggestion that scale over multiple (40+) projects would be highly appreciated.

BR,  
Jimisola

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [December 21, 2021, 11:07am UTC](https://community.sonarsource.com/t/sonar-badges-in-gitlab/54476/5 "2021-12-21T11:07:49Z")

</div>

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