-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-CD
99 lines (90 loc) · 2.54 KB
/
Jenkinsfile-CD
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!groovy
def publishOverSSH(SERVER_CONFIG_NAME) {
sshPublisher(
continueOnError: false, // 서버에 문제 발생 시 진행 여부
failOnError: true, // 서버에 배포시 문제가 생기면 빌드 실패로 표시 여부
publishers:[
sshPublisherDesc(
configName: "${SERVER_CONFIG_NAME}",
verbose: true,
transfers: [
sshTransfer(
execCommand: "bash deploy.sh"
)
]
)
]
)
}
pipeline {
agent any
environment {
REGISTRY_CREDENTIAL = 'docker-hub'
CURRENT_DATE = sh(returnStdout: true, script: 'date +%y%m%d').trim()
TAG = "$CURRENT_DATE.$BUILD_NUMBER"
dockerImage = ''
}
stages {
stage('build') {
steps {
sh 'chmod +x gradlew'
sh './gradlew clean build --exclude-task test --exclude-task asciidoctor'
echo 'build success'
}
}
stage('test') {
steps {
sh './gradlew test'
echo 'test success'
}
}
stage('build docker image') {
steps {
script {
dockerImage = docker.build("$IMAGE_NAME")
}
echo 'build docker image success'
}
}
stage('push docker image') {
steps {
script {
docker.withRegistry('', REGISTRY_CREDENTIAL) {
dockerImage.push("$TAG")
dockerImage.push('latest')
}
}
echo 'push docker image success'
}
}
stage('remove unused docker image') {
steps {
sh "docker rmi $IMAGE_NAME:$TAG"
sh "docker rmi $IMAGE_NAME:latest"
echo 'docker rmi success'
}
}
// Pulish Over SSH plugin 사용
stage('deploy') {
steps {
script {
def serverList = ["web1", "web2"]
for (server in serverList) {
stage(server) {
publishOverSSH(server)
}
}
}
echo 'deploy success'
}
}
}
post {
success {
echo 'success'
}
failure {
echo 'failure'
}
}
}