sonar quality gate
v1.3.2
Sonarqube具有高質量的代碼門,但對於社區版來說不起作用。因此,此插件將與CI/CD相交,獲取質量代碼,並在更改時將報告合併。
質量門是質量代碼門的命令行接口。
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如果設置為鮑洛參數:
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和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麻省理工學院。請參閱LICENDE.TXT。