From 028a3b0082820f6650edb38bd455bcc29e188346 Mon Sep 17 00:00:00 2001
From: Alexis POYEN <apoyen@grandlyon.com>
Date: Tue, 18 Mar 2025 15:39:01 +0000
Subject: [PATCH] update Sonarqube CI template

---
 .gitlab-ci.yml | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 80f9ab8..4ae76ba 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -6,24 +6,37 @@ variables:
 stages:
   - test
   - build
+  - sonar
 
 sonarqube-check:
+  stage: sonar
   image:
-    name: sonarsource/sonar-scanner-cli:4
+    name: sonarsource/sonar-scanner-cli:11
     entrypoint: [""]
   variables:
     SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
     GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
+    GIT_STRATEGY: clone # clone the repo in sonar job runner
+    SONAR_URL: http://sonarqube.forge.grandlyon.com:9000 # url to use for the sonarqube server
   cache:
     key: "${CI_JOB_NAME}"
     paths:
       - .sonar/cache
   script:
-    #- 'curl -X POST -H "Login: ${SONAR_TOKEN}" ${SONAR_URL}/api/project_branches/rename?name=main&project=${CI_PROJECT_NAME}'
-    - sonar-scanner -Dsonar.login=${SONAR_TOKEN} -Dsonar.projectName=${CI_PROJECT_NAME} -Dsonar.projectKey=${SONAR_PROJECT_KEY} -Dsonar.qualitygate.wait=true -Dsonar.host.url=${SONAR_URL}
-  allow_failure: true
-  only:
-    - main
+    - >
+      sonar-scanner 
+      -Dsonar.login=${SONAR_TOKEN} 
+      -Dsonar.projectName=${CI_PROJECT_NAME} 
+      -Dsonar.projectKey=${SONAR_PROJECT_KEY} 
+      -Dsonar.qualitygate.wait=true 
+      -Dsonar.host.url=${SONAR_URL}
+      -Dsonar.sourceEncoding=UTF-8
+      -Dsonar.projectBaseDir=.
+      -Dsonar.sources=src
+      -Dsonar.exclusions=**/main.ts,**/*.module.ts,**/*.spec.ts
+  rules:
+    - if: $CI_COMMIT_BRANCH == "main"
+      allow_failure: true
   tags:
     - build-push-to-registry
 
-- 
GitLab