Pull Request decoration 기능?
- SonarQube v7.2부터는 유료(Developer Edition)로 바뀜.
- 7.1 까진 무료 버전에서도 플러그인 형태로 제공.
- https://docs.sonarqube.org/display/PLUG/GitHub+Plugin
- https://github.com/SonarSource/sonar-github
- PR 시 changes만 가져와서 sonarqube 돌리게끔 설정 가능.
설치 및 초기 설정
- 일단 SonarQube 7.1 버전 설치. 최신 버전은 docker로도 설치할 수 있는데 7.1은 그냥 zip으로 받아서 압축 풀어 설치하면 됨.
- conf 설정 등 전체적인 권장사항은 이 것 참조 https://docs.sonarqube.org/7.1/InstallingtheServer.html
PostgreSQL 설치
- conf에서 설정 안해주면 임시로 H2를 사용하도록 되어 있는데, H2는 테스트 용으로만 사용해야 함(당연)
- 당연히 DB 쓰는게 좋고.. PostgreSQL이 오픈소스이므로 권장. (OracleXE는 개발 용으로만 사용 가능하고 상업 용도로 사용 불가)
- PostgreSQL 설치
- 설치 후 계정 만들고 sonarqube 라는 DB 하나 만들면 끝.
Jenkins 연동
- SonarQube에서 jenkins_token이라는 이름으로 토큰 발급 받고...
- jenkins - system configuration에서 토큰 사용하여 소나큐브 서버 연결해주고
- 플러그인 설치 탭에서 SonarQube Scanner 설치
- Global Tool Configuration에서 SonarQube Scanner installations 설정. ( 따로 직접 설치할 필요 없이 이렇게 설치 가능 )
Jenkins에서 SonarQube 트리거하기
- https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins/
- 결국 젠킨스에서 Command line으로 SonarScanner를 트리거 하냐, Maven으로 트리거 하냐, Gradle로 트리거 하냐 그 차이임.
- 관리는 Jenkins Pipeline으로 할 수도 있고, Freestyle 잡으로 할 수도 있는데... 이건 젠킨스 종속적인거라 상관 없음.
- 이번 케이스는 각 레포지토리 maven, gradle에 sonarscanner 관련 설정을 넣기 보단 command line으로 젠킨스에서 트리거 하도록 함.
- 이 방법도 괜찮긴 한데... sonar.java.libraries 를 명시하려면 m2 전체를 명시하든가 해야한다는 점은 단점. 뭐 그냥 libraries 옵션 안줘도 그닥 나쁘진 않을 듯.
- Analyzing other project types 섹션과 https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/ 를 참고.
```bash
# must be unique in a given SonarQube instance
sonar.projectKey={my}:{key}
# Path is relative to the sonar-project.properties file. Defaults to .
sonar.sources=.
# 예전에는 .java 파일만 가지고 정적 분석을 수행했는데, 이제는 .class 파일도 필요하다. 그래서 sonar.java.binaries 지정해주어야 하고,
# Scanner 잡 이전에 build 잡을 넣어주어 .class를 생성해주어야 한다.
sonar.java.binaries=./target/classes
# defaults to 'not provided'
#sonar.projectVersion=1.0
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
# --- GitHub Plugin PR decoration settings ---
sonar.github.endpoint=https://example.github.enterprise.url/api/v3
sonar.github.repository=${ghprbGhRepository}
sonar.github.pullRequest=${ghprbPullId}
sonar.github.oauth=${githubAccessToken}
sonar.analysis.mode=preview
sonar.github.disableInlineComments=true
```
'DevOps & Server' 카테고리의 다른 글
SonarQube (0) | 2020.12.08 |
---|---|
NGINX (0) | 2020.12.04 |
[tomcat] 톰캣, jvm 실행 인자 (0) | 2020.03.05 |
젠킨스 Jenkins (0) | 2019.05.09 |
[Gradle] build, jar 배포, IntelliJ 설정 (0) | 2019.04.10 |
vagrant (0) | 2018.11.02 |