Sonarqube имеют качественные кодовые ворота, но это не работа для сообщества. Таким образом, этот плагин будет взаимосвязан в CI/CD, получить код качества и отчет о том, чтобы слияние, когда он будет изменен.
Gate-Gate -это интерфейс командной строки для качественного кода.
sonar-scanner для аналитического кода, сообщать и выдвигать проблемы на Sonar Servers.Для GitHub и Gitlab
Результат:
$ npm install -g sonar-quality-gate
# Show help
$ quality-gate --helpРезультат:
__ _ _ _ __ _ | | (_) | | _ _ _ __ _ __ _ | | _ ___
/ _ ` | | | | | / _ ` | | | | | | __ | | | | | _____ / _ ` | / _ ` | | __ | / _
| (_ | | | | _ | | | (_ | | | | | | | | _ | | _ | | | _____ | | (_ | | | (_ | | | | _ | __/
_ _, | _ _,_ | _ _,_ | | _ | | _ | _ _ | _ _, | _ _, | _ _,_ | _ _ | _ __ |
| _ | | ___/ | ___/
Usage: quality-gate [options]
Global Options:
-h, --help [boolean]
-D, --define Define sonar property
Authentication:
sonar.login The authentication token or login of a SonarQube user with Execute Analysis permission on
the project.
More parameters:
- https://docs.sonarqube.org/latest/analysis/analysis-parameters/ [array]
--git Config git
--git.url Git server URL. Default: $GIT_URL
--git.token Git token. Default: $GIT_TOKEN
--git.project_id Gitlab project ID or Github repository. Default: $CI_PROJECt_ID or $GITHUB_REPOSITORY
--git.merge_id Git merge request IID. Default: $CI_MERGE_REQUEST_IID
[default: {}]
--sonar Config sonar
--sonar.url Sonarqube server URL. Default: $SONAR_URL or sonar.host.url in file
sonar-project.properties.
--sonar.token The authentication token of a SonarQube user with Execute Analysis permission on the
project. Default: $SONAR_TOKEN
--sonar.project_key Sonar project key. Default: sonar.projectKey in file sonar-project.properties
[default: {}]
-v, --version Show version [boolean]
-X, --debug Produce execution debug output [boolean] [default: false]
-p, --provide [default: " gitlab " ]Чтобы запустить, проверить качественный код ворота:
quality-gate -p=github -D sonar.login= " <token> " --sonar.url= " <sonar url> " --sonar.token= " <sonar token> " --sonar.project_key= " <sonar token> " --git.url= " https://gitlab.com " --git.token= " xxx " --git.project_id=123 --git.merge_id=345Если установлен Env для более реже параметров:
GIT_URL= " "
GIT_TOKEN= " "
CI_PROJECt_ID= " "
CI_MERGE_REQUEST_IID= " "
SONAR_URL= " "
SONAR_TOKEN= " " и имеет файл sonar-project.properties :
sonar.host.url=
sonar.projectKey=
Мы можем использовать короткую команду:
quality-gate -Dsonar.login= " " Добавьте новый файл sonar-project.properties , как показано ниже Содержание:
# sonar.organization=dieuhd # if use sonarcloud, uncomment this line
sonar.host.url=[SONAR_HOST]
sonar.projectKey=[SONAR_PROJECT_KEY]
sonar.qualitygate.wait=true
Ссылка: Sonar-Project.properties
Используйте quality-gate вместо sonar-scanner .
Пример:
quality-gate -Dsonar.login= $SONAR_KEYИ config для gitlab-ci:
stages :
- CheckSonar
.CheckSonarqube : &CheckSonarqube |
quality-gate -Dsonar.login=$SONAR_KEY
Sonar :
stage : CheckSonar
image : dieuhd/sonar-quality-gate
rules :
- if : ' $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" '
script :
- *CheckSonarqubeP/S: Работа только для запроса слияния. Поскольку плагин нуждается в запросе слияния IID.
Пример:
name : Check sonarqube
on : [pull_request]
jobs :
build :
name : Build
runs-on : ubuntu-latest
steps :
- name : Checkout
uses : actions/[email protected]
with :
fetch-depth : 0 # Shallow clones should be disabled for a better relevancy of analysis
- name : Set up Sonar Quality Gate
uses : dieuhd/sonar-quality-gate@v1
env :
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
GIT_URL : " https://api.github.com "
GIT_TOKEN : ${{ secrets.GIT_TOKEN }}
SONAR_URL : ${{ secrets.SONAR_URL }}
SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
SONAR_PROJECT_KEY : ${{ secrets.SONAR_PROJECT_KEY }}
with :
login : ${{ secrets.SONAR_TOKEN }}
url : ${{ secrets.SONAR_URL }}
projectKey : ${{ secrets.SONAR_PROJECT_KEY }} $ git clone https://github.com/dieuhd/sonar-quality-gate.git
$ cd sonar-quality-gate
$ npm install
$ husky install && chmod ug+x .husky/ *
$ npm run start:devГрань См. License.txt.