Что говорит официальная документация: < /p>
Код: Выделить всё
sonarqube-check:
image: maven:3.6.3-jdk-11
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 -Dsonar.qualitygate.wait=true
allow_failure: true
only:
- merge_requests
- master # or the name of your main branch
- develop
и я обнаружил (и проверял на всякий случай) MVN Sonar: Sonar получает свой Конфигурации из командной строки (с -снар.x = y параметры) и POM. Он не читает Sonar -project.properties. используют Jenkins+Bitbucket и Gitlab параллельно с зеркалированием, так что, возможно, в будущем мы, вероятно, закончим обновлять POM. Скрипт с командами «SED» для извлечения -donar.* Описания к переменной, которая была добавлена в команду Pipelines. < /p>
sonar:
stage: validate
image: maven:3-jdk-11
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
GIT_DEPTH: "1" # Tells git to fetch specific branch
SONAR_HOST_URL: http://your url
before_script:
- sed -e 's|^| -D|g' sonar-project.properties | grep "sonar." >> props.txt //exports only line with sonar. and write it in new file with -Dsonar.
- sed -i '/-D#/d' props.txt // removed in case setting is commented out
- sed -i '/-Dm/d' props.txt // removed lines that does not go with specifications(in my case that was module description)*
- sed -i '/-Dsonar.modules/d' props.txt // removed modules *'cos it gave error with folder name duplication on Sonar Scan
- export SONAR_PROPS=$(sed 's/["\n\r]//g' props.txt) // exported that file to single-line variable
- rm -rf props.txt
script:
- echo $SONAR_PROPS
# - mvn verify sonar:sonar -Dsonar.login=$SONAR_LOGIN -Dsonar.password=$SONAR_PASSWORD $SONAR_PROPS
allow_failure: true
when: manual
< /code>
Это было мое быстрое решение для использования Sonar-project.properties в команде MVN. Использует те же файлы, что и Jenkins.
Подробнее здесь: https://stackoverflow.com/questions/745 ... -gitlab-ci
Мобильная версия