From c44a43d575c8a81abe972b30aeca5038bb39e0a6 Mon Sep 17 00:00:00 2001
From: Pierre Smeyers <pierre.smeyers@gmail.com>
Date: Wed, 6 Jul 2022 19:23:49 +0200
Subject: [PATCH] feat: manage Sonar task cache in GitLab

---
 templates/gitlab-ci-sonar.yml | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/templates/gitlab-ci-sonar.yml b/templates/gitlab-ci-sonar.yml
index d9f4750..f810e6b 100644
--- a/templates/gitlab-ci-sonar.yml
+++ b/templates/gitlab-ci-sonar.yml
@@ -179,7 +179,7 @@ stages:
     fi
   }
 
-
+  
   function unscope_variables() {
     _scoped_vars=$(env | awk -F '=' "/^scoped__[a-zA-Z0-9_]+=/ {print \$1}" | sort)
     if [[ -z "$_scoped_vars" ]]; then return; fi
@@ -303,9 +303,13 @@ sonar:
     - name: "$TBC_TRACKING_IMAGE"
       command: ["--service", "sonar", "3.0.0" ]
   variables:
-    # Tells git to fetch all the branches of the project, required by the analysis task
-    # see: https://docs.sonarqube.org/8.5/analysis/gitlab-cicd/#header-2
-    GIT_DEPTH: 0
+    # see: https://docs.sonarqube.org/latest/analysis/gitlab-integration/#header-4
+    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
+  cache:
+    key: "sonar"
+    paths:
+      - .sonar/cache
   before_script:
     - *sonar-scripts
     - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
-- 
GitLab