From 9e8cd3b6c34c95cd98b52c9d3ef069ced8f1a27a Mon Sep 17 00:00:00 2001 From: Thilo Schwarz Date: Sun, 6 Apr 2025 18:09:56 +0200 Subject: [PATCH] Optimize GitLab CI configuration for SonarCloud integration Added support for caching SonarCloud analysis tasks and updated the Git depth setting to ensure proper branch --- .gitlab-ci.yml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 82c6dac..6b9a9ca 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,6 +13,8 @@ variables: SONAR_PROJECT_KEY: "th-schwarz_DynDRest" SONAR_ORGANIZATION: "th-schwarz" SONAR_TOKEN: "${SONAR_TOKEN_ENV_VAR}" + 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 pull_source: @@ -24,7 +26,6 @@ pull_source: only: - schedules - on_commits: stage: on_commit script: @@ -33,19 +34,20 @@ on_commits: - mvn clean test only: - /^feature.*$/ + - merge_request - develop sonarcloud_scan: stage: sonarcloud_scan + image: + name: sonarsource/sonar-scanner-cli:latest + entrypoint: [""] + cache: + key: "${CI_JOB_NAME}" + paths: + - .sonar/cache script: - - echo "Setting up SonarCloud scan..." - - cd ${GITLAB_CLONE_DIR} - - | - mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \ - -Dsonar.host.url=${SONAR_HOST_URL} \ - -Dsonar.projectKey=${SONAR_PROJECT_KEY} \ - -Dsonar.organization=${SONAR_ORGANIZATION} \ - -Dsonar.login=${SONAR_TOKEN} - + - sonar-scanner only: + - merge_requests - develop