sonar quality gate
v1.3.2
Sonarqube에는 품질 코드 게이트가 특징이지만 커뮤니티 에디션에는 효과가 없습니다. 따라서이 플러그인은 CI/CD 로의 GATE로, 품질 코드를 가져 와서 변경 사항이 변경 될 때 요청을 병합하도록 보고서를 푸시합니다.
품질-게이트 는 품질 코드 게이트의 명령 줄 인터페이스입니다.
sonar-scanner 사용하여 분석 코드,보고 및 문제를 소나 서버에 푸시하십시오.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
sonar-scanner 대신 quality-gate 사용하십시오.
예:
quality-gate -Dsonar.login= $SONAR_KEYgitlab-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 : 병합 요청에만 해당됩니다. Becase, 플러그인은 병합 요청 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:devMIT. license.txt를 참조하십시오.