Sonarqube ?
정적분석을 위한 Sonarqube 설치
1. host 설정
# max_map_count ?
This file contains the maximum number of memory map areas a process may have. Memory map areas are used as a side-effect of calling malloc, directly by mmap and mprotect, and also when loading shared libraries.
While most applications need less than a thousand maps, certain programs, particularly malloc debuggers, may consume lots of them, e.g., up to one or two maps per allocation.
The default value is 65536.3. Compose 파일 작성
version: "3.7"
services:
db:
image: postgres
container_name: sonar-postgres
restart: always
environment:
POSTGRES_USER: sonar
PASTGRES_PASSWORD: sonar
TZ: Asia/Seoul
POSTGRES_HOST_AUTH_METHOD: trust
volumes:
- ~/docker-volumes/sonar-postgres/postgres:/var/lib/postgresql/data
sonarqube:
image: sonarqube:8.6.1-developer
container_name: sonarqube
restart: always
environment:
SONARQUBE_HOME: ./
SONARQUBE_JDBC_USERNAME: sonar
SONARQUBE_JDBC_PASSWORD: sonar
SONARQUBE_JDBC_URL: jdbc:postgresql://db:5432/sonar
depends_on:
- db
ports:
- 10002:9000
volumes:
- ~/docker-volumes/sonar-postgres/sonarqube/data:/opt/sonarqube/data
- ~/docker-volumes/sonar-postgres/sonarqube/extensions:/opt/sonarqube/extensions
- ~/docker-volumes/sonar-postgres/sonarqube/logs:/opt/sonarqube/logs
- ~/docker-volumes/sonar-postgres/temp:/opt/sonarqube/temp4. 서비스 기동
$ docker-compose -f sonarqube-compose.yml up -d정적분석을 위한 Sonarqube 프로젝트 생성 및
1. Sonarqube 프로젝트 생성
2. Scanner 설정 및 실행
plugins {
id "org.sonarqube" version "3.0"
}./gradlew sonarqube \
-Dsonar.projectKey=Test-Proj \
-Dsonar.host.url=http://HOST:10002 \
-Dsonar.login=***********************Pipeline 작성 1. Test Stage
stage ('Test') {
sh '''
{
./gradlew test \
&& curl -X POST -u "$USER" $COMMENT_URL -d '{"content": {"raw": "[TEST] SUCCESS"}}' -H 'Content-Type: application/json' > /dev/null 2>&1 \
&& echo [TEST] SUCCESS;
}||\
{
ssh -ir ~/.ssh/v2g_srv $V2G_DEV_SERVER bash -c "'mkdir -p /docker-volumes/nginx/html/failed-test/$SOURCE_BRANCH'";
scp -ir ~/.ssh/v2g_srv ./build/reports/tests/test $V2G_DEV_SERVER:/docker-volumes/nginx/html/failed-test/$SOURCE_BRANCH;
curl -X POST -u "$USER" $COMMENT_URL -d '{"content": {"raw": "[TEST] FAIL"}}' -H 'Content-Type: application/json' > /dev/null 2>&1;
curl -X POST -u "$USER" $DECLINE_URL -d '{"content": {"raw": "[TEST] FAIL"}}' -H 'Content-Type: application/json' > /dev/null 2>&1;
echo [TEST] FAIL;
exit 1;
}
'''
}2. Jacoco & SonarQube Analysis & Quality Gate
stage ('Jacoco & SonarQube Analysis & Quality Gate') {
withSonarQubeEnv('sonarqube') {
sh "./gradlew jacocoTestReport sonarqube"
}
def qg = waitForQualityGate()
if (qg.status != 'OK') {
sh '''
curl -X POST -u "$USER" $COMMENT_URL -d '{"content": {"raw": "[QualityGate] FAIL"}}' -H 'Content-Type: application/json' > /dev/null 2>&1;
curl -X POST -u "$USER" $DECLINE_URL -d '{"content": {"raw": "[QualityGate] FAIL"}}' -H 'Content-Type: application/json' > /dev/null 2>&1;
echo [TEST] FAIL;
exit 1;
'''
} else {
sh '''
curl -X POST -u "$USER" $COMMENT_URL -d '{"content": {"raw": "[QualityGate] SUCCESS"}}' -H 'Content-Type: application/json' > /dev/null 2>&1;
'''
}
}3. Approve PullRequest
stage ('Approve PR') {
timeout(time: 1, unit: 'MINUTES') {
sh '''
curl -X POST -u "$USER" $APPROVE_URL;
echo Approve PullRequest;
'''
}
}> [작업로그] CI/CD 구축 #1 - CI/CD 시나리오
> [작업로그] CI/CD 구축 #2 - Docker, Docker Compose 설치
> [작업로그] CI/CD 구축 #3 - BitBucket 설정 및 Jenkins 설치
> [작업로그] CI/CD 구축 #4 - Jenkins Item 등록 및 Pipeline 작성