Slack 연결
- 목적: ChatOps
- slack 채널 생성(무료플랜)
- Jenkins Plugin 설치
- slack 앱 추가
- Jenkins에 slack 연결
- 연결 확인
# Jenkinsfile
node {
// job
try {
stage('build') {
println('so far so good...')
}
stage('test') {
println('A test has failed!')
sh 'exit 1'
}
} catch(e) {
// mark build as failed
currentBuild.result = "FAILURE";
// send slack notification
slackSend (color: '#FF0000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
// throw the error
throw e;
}
}
Sonarqube 연결
- docker-compose 활용하여 Sonarqube 설치
mkdir jenkins
cd jenkins
vi docker-compse.yml
# docker compose 설치
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
docker-compse up -d
#docker-compose.yml
version: '2'
services:
jenkins:
image: jenkins-docker:latest
ports:
- "8080:8080"
- "50000:50000"
networks:
- jenkins
volumes:
- /var/jenkins_home:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
postgres:
image: postgres:9.6
networks:
- jenkins
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonarpasswd
volumes:
- /var/postgres-data:/var/lib/postgresql/data
sonarqube:
image: sonarqube:lts
ports:
- "9000:9000"
- "9092:9092"
networks:
- jenkins
environment:
SONARQUBE_JDBC_USERNAME: sonar
SONARQUBE_JDBC_PASSWORD: sonarpasswd
SONARQUBE_JDBC_URL: "jdbc:postgresql://postgres:5432/sonar"
depends_on:
- postgres
networks:
jenkins:
- 인스턴스 9000번 포트 열어주고 확인해보자 (소나큐브 설치 완료되었는지 확인)
- Jenkins pipeline을 통해 Sonarqube 통합
- Sonarqube Scanner for Jenkins 플러그인 설치
- 이후 Jenkinsfile에 코드 넣어두면 된다! (sonar-scanner 부분)
node {
def myGradleContainer = docker.image('gradle:jdk8-alpine')
myGradleContainer.pull()
stage('prep') {
git url: 'https://github.com/wardviaene/gs-gradle.git'
}
stage('build') {
myGradleContainer.inside("-v ${env.HOME}/.gradle:/home/gradle/.gradle") {
sh 'cd complete && /opt/gradle/bin/gradle build'
}
}
stage('sonar-scanner') {
def sonarqubeScannerHome = tool name: 'sonar', type: 'hudson.plugins.sonar.SonarRunnerInstallation'
withCredentials([string(credentialsId: 'sonar', variable: 'sonarLogin')]) {
sh "${sonarqubeScannerHome}/bin/sonar-scanner -e -Dsonar.host.url=http://sonarqube:9000 -Dsonar.login=${sonarLogin} -Dsonar.projectName=gs-gradle -Dsonar.projectVersion=${env.BUILD_NUMBER} -Dsonar.projectKey=GS -Dsonar.sources=complete/src/main/ -Dsonar.tests=complete/src/test/ -Dsonar.language=java -Dsonar.java.binaries=."
}
}
}
'Computer Science > DevOps' 카테고리의 다른 글
[AWS] WEB - WAS 구성 (Apache - Tomcat) (0) | 2023.07.27 |
---|---|
[Jenkins] Jenkins Pipeline 구축 (0) | 2023.07.03 |
[Jenkins] Jenkins 다뤄보기 (0) | 2023.06.27 |
[OS] OS 모음집 (0) | 2021.08.12 |
[CI/CD] Tool (0) | 2021.08.11 |