stages:
  - sonarqube_stage

sonarqube_master_job:
  stage: sonarqube_stage
  only:
    - master
  script:
    - git pull origin master
    - echo $CI_PROJECT_PATH_SLUG
    - echo $CI_PROJECT_ID-$CI_JOB_ID
    - mvn --batch-mode verify sonar:sonar
      -Dsonar.host.url=http://192.168.92.120:9000/
      -Dsonar.login=admin
      -Dsonar.password=admin
      -Dsonar.projectKey=$CI_PROJECT_PATH_SLUG
      -Dsonar.projectName=$CI_PROJECT_PATH_SLUG
      -Dsonar.sourceEncoding=UTF-8
      -Dsonar.projectVersion=$CI_PROJECT_ID-$CI_JOB_ID
      -Dsonar.ce.workerCount=1
      -Dsonar.language=java
      -Dsonar.forceAnalysis=true
      -Dsonar.java.binaries=target/classes
      -Dsonar.sources=src/main/java
      -Dprod
      -Dreversion=3.1.1-RELEASE
      
# code review
sonarqube_preview_feature_job:
  stage: sonarqube_stage
  only:
    - /^feature\/*/
    - /^fixbug\/*/
  script:
    - git checkout origin/master
    - git pull origin master
    - git merge $CI_COMMIT_SHA --no-commit --no-ff
    - mvn --batch-mode verify sonar:sonar 
        -Dsonar.host.url=http://192.168.92.120:9000/ 
        -Dsonar.login=admin 
        -Dsonar.password=admin 
        -Dsonar.analysis.mode=preview 
        -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA 
        -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME 
        -Dsonar.gitlab.project_id=$CI_PROJECT_ID
        -Dprod
        -Dreversion=3.1.1-RELEASE
