O Sonarqube possui portão de código de qualidade, mas não funciona para a Community Edition. Portanto, este plug -in será intergido para CI/CD, obtenha código de qualidade e empurre o relatório para mesclar a solicitação quando tiver alteração.
A qualidade da qualidade é uma interface da linha de comando para o portão de código de qualidade.
sonar-scanner de comando para código analítico, relatar e empurrar problemas para os servidores do sonar.Para Github e Gitlab
Resultado:
$ npm install -g sonar-quality-gate
# Show help
$ quality-gate --helpResultado:
__ _ _ _ __ _ | | (_) | | _ _ _ __ _ __ _ | | _ ___
/ _ ` | | | | | / _ ` | | | | | | __ | | | | | _____ / _ ` | / _ ` | | __ | / _
| (_ | | | | _ | | | (_ | | | | | | | | _ | | _ | | | _____ | | (_ | | | (_ | | | | _ | __/
_ _, | _ _,_ | _ _,_ | | _ | | _ | _ _ | _ _, | _ _, | _ _,_ | _ _ | _ __ |
| _ | | ___/ | ___/
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 " ]Para executar a verificação do portão de código de qualidade:
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=345Se definido Env para parâmetros abaixo:
GIT_URL= " "
GIT_TOKEN= " "
CI_PROJECt_ID= " "
CI_MERGE_REQUEST_IID= " "
SONAR_URL= " "
SONAR_TOKEN= " " e tem arquivos sonar-project.properties :
sonar.host.url=
sonar.projectKey=
Podemos usar o comando curto:
quality-gate -Dsonar.login= " " Adicione um novo arquivo de arquivo sonar-project.properties como abaixo do conteúdo:
# sonar.organization=dieuhd # if use sonarcloud, uncomment this line
sonar.host.url=[SONAR_HOST]
sonar.projectKey=[SONAR_PROJECT_KEY]
sonar.qualitygate.wait=true
Ref: Sonar-Project.Properties
Use quality-gate em vez de sonar-scanner .
Exemplo:
quality-gate -Dsonar.login= $SONAR_KEYE config para 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: trabalhe apenas para solicitação de mesclagem. Porque, o plug -in precisa de solicitação de mesclagem iid.
Exemplo:
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. Veja License.txt.