...
Jenkins에서 SonarQube 품질 게이트 실패 시 파이프라인 자동 실패 처리
SonarQube 서버에서 프로젝트에 대한 웹훅을 구성합니다추가합니다.
URL에 <yourJenkinsInstance>/sonarqube-webhook/를 입력합니다.
Jeknins 파일에 아래와 같이 waitForQualityGate단계를 추가합니다.
- Scripted pipeline코드 블럭 node { stage('SonarQube analysis') { withSonarQubeEnv('<sonarqubeInstallation>') { sh 'mvn clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar' } // submitted SonarQube taskId is automatically attached to the pipeline context } } // No need to occupy a node stage("Quality Gate"){ timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv if (qg.status != 'OK') { error "Pipeline aborted due to quality gate failure: ${qg.status}" } } }
GitLab Merge Request에서 모든 Pipeline 성공 조건 설정
GitLab 프로젝트의 Settings > General > Merge requests로 이동합니다.
Merge checks 섹션에서 Pipelines must succeed를 선택합니다.
Save changes를 클릭하여 변경 사항을 저장합니다.
품질게이트 실패 시, Jenkins 파이프라인이 실패하며 GitLab에서 Merge가 Block됩니다.
...
참고
...