From 9a35ee656e685468fc85c1e567c0c649db2d352a Mon Sep 17 00:00:00 2001
From: "Saralegui Vallejo, Unai" <unai.saralegui@tecnalia.com>
Date: Tue, 18 May 2021 08:26:26 +0200
Subject: [PATCH] add sonarqube check for maven

---
 maven-packages/README.md     |  4 ++++
 maven-packages/sonarqube.yml | 17 +++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100644 maven-packages/sonarqube.yml

diff --git a/maven-packages/README.md b/maven-packages/README.md
index a63c007..f373005 100644
--- a/maven-packages/README.md
+++ b/maven-packages/README.md
@@ -5,6 +5,7 @@ You can include the jobs in this repository's YAML files as follows:
 ```yml
 include:
   - https://git.code.tecnalia.com/digicon-webxr-store/ci-files/-/raw/master/maven-packages/build.yml
+  - https://git.code.tecnalia.com/digicon-webxr-store/ci-files/-/raw/master/maven-packages/sonarqube.yml
   - https://git.code.tecnalia.com/digicon-webxr-store/ci-files/-/raw/master/maven-packages/tests.yml
   - https://git.code.tecnalia.com/digicon-webxr-store/ci-files/-/raw/master/maven-packages/deploy.yml
 ```
@@ -14,6 +15,7 @@ You can include the execution order in yout .gitlab-ci.yml file as follows:
 ```yml
 stages:
   - build
+  - code_analysis
   - test
   - deploy
 ```
@@ -35,6 +37,7 @@ An example of a valid .gitlab-ci.yml can be:
 ```yml
 include:
   - https://git.code.tecnalia.com/digicon-webxr-store/ci-files/-/raw/master/maven-packages/build.yml
+  - https://git.code.tecnalia.com/digicon-webxr-store/ci-files/-/raw/master/maven-packages/sonarqube.yml
   - https://git.code.tecnalia.com/digicon-webxr-store/ci-files/-/raw/master/maven-packages/tests.yml
   - https://git.code.tecnalia.com/digicon-webxr-store/ci-files/-/raw/master/maven-packages/deploy.yml
 
@@ -43,6 +46,7 @@ variables:
 
 stages:
   - build
+  - code_analysis
   - test
   - deploy
 
diff --git a/maven-packages/sonarqube.yml b/maven-packages/sonarqube.yml
new file mode 100644
index 0000000..82504ce
--- /dev/null
+++ b/maven-packages/sonarqube.yml
@@ -0,0 +1,17 @@
+sonarqube-check:
+  image: maven:3.6.3-jdk-11
+  tags:
+    - docker
+  stage: code_analysis
+  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
+  cache:
+    key: "${CI_JOB_NAME}"
+    paths:
+      - .sonar/cache
+  script: 
+    - mvn verify sonar:sonar
+  allow_failure: true
+  only:
+    - master # or the name of your main branch
-- 
GitLab