구축하고자 하는 환경
CI
CD
1. 설치
1
2
3
4
5
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo yum install jenkins
sudo systemctl daemon-reload
2. 접속 후 플러그인 설치 (+ Jenkins 관리 -> System)
2.1 플러그인 설치
SSH
Docker
Git
2.2 젠킨스 접속 경로 등록 (Jenkins Location 탭)
2.3 원격 서버 정보 등록 (SSH Server 탭)
3. Credentials 등록
4. GitHub Webhook 설정
5. 파이프라인 구축
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
pipeline {
agent any
environment {
HARBOR_URL = 'masking'
HARBOR_PROJECT = 'masking'
API_IMAGE_NAME = 'masking'
IMAGE_TAG = '0.1'
LATEST_IMAGE_TAG = 'latest'
DOCKER_REGISTRY_CREDENTIALS_ID = credentials('harbor')
NEXUS_CREDENTIALS = credentials('nexus')
NEXUS_USERNAME = "${NEXUS_CREDENTIALS_USR}"
NEXUS_SECRET = "${NEXUS_CREDENTIALS_PSW}"
}
triggers {
githubPush()
}
stages {
stage('개발 브랜치 접근') {
steps {
checkout([
$class : 'GitSCM',
branches : [[name: 'develop']],
userRemoteConfigs: [[url: 'masking', credentialsId: 'masking']]
])
}
}
stage('프로젝트 빌드') {
steps {
sh 'chmod +x gradlew'
sh "./gradlew clean bootJar"
}
}
stage('API 모듈 이미지 빌드 및 업로드') {
steps {
script {
def buildAndPushImage = {
def fullImageName = "${HARBOR_URL}/${HARBOR_PROJECT}/${API_IMAGE_NAME}:${IMAGE_TAG}"
def latestFullImageName = "${HARBOR_URL}/${HARBOR_PROJECT}/${API_IMAGE_NAME}:${LATEST_IMAGE_TAG}"
sh "docker build -t ${fullImageName} ./masking/"
sh "docker tag ${fullImageName} ${latestFullImageName}"
docker.withRegistry("https://${HARBOR_URL}", 'masking') {
docker.image(fullImageName).push()
docker.image(latestFullImageName).push()
}
}
buildAndPushImage('masking', API_IMAGE_NAME, HARBOR_PROJECT)
}
}
}
stage('API 모듈 배포 스크립트 실행') {
steps {
script {
sshPublisher(
publishers: [
sshPublisherDesc(
configName: "SSH Server 탭에 등록한 Name",
transfers: [
sshTransfer(
execCommand: "masking.sh"
)
]
)
]
)
}
}
}
}
post {
success {
echo '배포 성공'
}
failure {
echo '배포 실패'
}
}
}