Sonar Scanner для GitLab CI/CD и Jenkins.
docker pull astrizhachuk/sonar-scanner-cli:latest
- adoptopenjdk:16-hotspot
- curl
- git
- git-lfs
- openssh-client
- unzip
- SONAR_SCANNER_VERSION="4.6.2.2472" - version of Sonar Scanner
stages:
- sonarqube
variables:
MAJOR: "10.3.1"
PATH_SRC: "src/"
merge_request:
stage: sonarqube
image:
name: ${CI_REGISTRY}/devops/sonar-scanner-cli:latest
entrypoint: [""]
variables:
GIT_DEPTH: 0
script:
- keytool -cacerts -storepass changeit -noprompt -trustcacerts -importcert -alias yours.serts.local -file "$SONAR_SSL_CERTIFICATE"
- export PROJECT_VERSION="${MAJOR}.$(grep -oPm1 "(?<=<VERSION>)[^<]+" ${PATH_SRC}VERSION)"
- export SONAR_SCANNER_OPTS="-Xmx16g"
- sonar-scanner
-D"sonar.host.url=${SONAR_SERVER}"
-D"sonar.projectVersion=${PROJECT_VERSION}"
-D"sonar.login=${SONAR_LOGIN}"
-D"sonar.pullrequest.key=${CI_MERGE_REQUEST_IID}"
-D"sonar.pullrequest.branch=${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME}"
-D"sonar.pullrequest.base=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
tags:
- docker
push:
stage: sonarqube
image:
name: ${CI_REGISTRY}/devops/sonar-scanner-cli:latest
entrypoint: [""]
variables:
GIT_DEPTH: 0
script:
- keytool -cacerts -storepass changeit -noprompt -trustcacerts -importcert -alias yours.serts.local -file "$SONAR_SSL_CERTIFICATE"
- export PROJECT_VERSION="${MAJOR}.$(grep -oPm1 "(?<=<VERSION>)[^<]+" ${PATH_SRC}VERSION)"
- export SONAR_SCANNER_OPTS="-Xmx6g"
- sonar-scanner
-D"sonar.host.url=${SONAR_SERVER}"
-D"sonar.projectVersion=${PROJECT_VERSION}"
-D"sonar.branch.name=master"
-D"sonar.login=${SONAR_LOGIN}"
rules:
- if: '$CI_COMMIT_TAG != null'
tags:
- docker