From 59ecffc86adf0e7462d2f28f0cb1928b0ebc24a3 Mon Sep 17 00:00:00 2001 From: Thilo Schwarz Date: Sat, 5 Apr 2025 20:46:43 +0200 Subject: [PATCH] Add SonarCloud integration and enhance CI stages Introduced SonarCloud scan and testing stages to the CI pipeline. Defined variables for SonarCloud and added a new `on_commit` stage for running tests. Updated the `.gitlab-ci.yml` configuration to improve project quality checks and automation. --- .gitlab-ci.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6c76df9..7ffd4b2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,8 +1,18 @@ +default: + image: maven:3.8.6-corretto-17 + stages: - pull + - on_commit + - sonarcloud_scan variables: GITLAB_CLONE_DIR: "cloudflaredns-java" + SONAR_HOST_URL: "https://sonarcloud.io" + SONAR_PROJECT_KEY: "th-schwarz_DynDRest" + SONAR_ORGANIZATION: "th-schwarz" + SONAR_TOKEN: "${SONAR_TOKEN_ENV_VAR}" + pull_source: stage: pull @@ -12,3 +22,27 @@ pull_source: - echo "Repository cloned successfully." only: - schedules + + +on_commits: + stage: on_commit + script: + - echo "Running tests..." + - cd ${GITLAB_CLONE_DIR} + - mvn clean test + only: + - /^feature.*$/ + - develop + +sonarcloud_scan: + stage: sonarcloud_scan + script: + - echo "Setting up SonarCloud scan..." + - cd ${GITLAB_CLONE_DIR} + - mvn sonar:sonar \ + -Dsonar.host.url=${SONAR_HOST_URL} \ + -Dsonar.projectKey=${SONAR_PROJECT_KEY} \ + -Dsonar.organization=${SONAR_ORGANIZATION} \ + -Dsonar.login=${SONAR_TOKEN} + only: + - develop