-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile-develop
More file actions
162 lines (161 loc) · 5.48 KB
/
Jenkinsfile-develop
File metadata and controls
162 lines (161 loc) · 5.48 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
pipeline {
agent any
options {
timeout(time: 1, unit: 'HOURS') // set timeout 1 hour
}
environment {
TIME_ZONE = 'Asia/Seoul'
REPOSITORY_CREDENTIAL_ID = 'all-knu-backend-jenkins-github-key' // github repository credential name
REPOSITORY_URL = 'git@github.com:1sTeam/all-knu-backend.git'
TARGET_BRANCH = 'develop'
IMAGE_NAME = 'all-knu-backend-develop'
CONTAINER_NAME = 'all-knu-backend-develop'
PROFILE = 'develop'
DOCKER_NETWORK = 'all-knu-haproxy-net'
LOGGING_HOST_PATH = '/home/aunae/all-knu-projects/log/all-knu-backend'
}
stages {
stage('init') {
steps {
echo 'init stage'
deleteDir()
}
post {
success {
echo 'success init in pipeline'
}
failure {
slackSend(channel: '#jenkins-notification', color: '#FF0000', message: "${env.CONTAINER_NAME} CI / CD 파이프라인 구동 실패, 젠킨스 확인 해주세요")
error 'fail init in pipeline'
}
}
}
stage('clone project') {
steps {
git url: "$REPOSITORY_URL",
branch: "$TARGET_BRANCH",
credentialsId: "$REPOSITORY_CREDENTIAL_ID"
sh "ls -al"
}
post {
success {
echo 'success clone project'
}
failure {
slackSend(channel: '#jenkins-notification', color: '#FF0000', message: "${env.CONTAINER_NAME} CI / CD 파이프라인 구동 실패, 젠킨스 확인 해주세요")
error 'fail clone project' // exit pipeline
}
}
}
stage('create secret file by aws parameter store') {
steps {
dir('src/main/resources/secrets') {
withAWSParameterStore(credentialsId: 'aws-all-knu',
path: "/all-knu/jwt/${env.PROFILE}",
naming: 'basename',
regionName: 'ap-northeast-2') {
writeFile file: 'jwt-secrets.properties', text: "${env.KEY}"
}
}
}
post {
success {
echo 'success create secret file'
}
failure {
slackSend(channel: '#jenkins-notification', color: '#FF0000', message: "${env.CONTAINER_NAME} CI / CD 파이프라인 구동 실패, 젠킨스 확인 해주세요")
error 'fail create secret file'
}
}
}
stage('create api endpoint secret file by aws parameter store') {
steps {
dir('src/main/resources/secrets') {
withAWSParameterStore(credentialsId: 'aws-all-knu',
path: "/all-knu/api-endpoint",
naming: 'basename',
regionName: 'ap-northeast-2') {
writeFile file: 'api-endpoint-secrets.yml', text: "${env.KNU}"
}
}
}
post {
success {
echo 'success create secret file'
}
failure {
slackSend(channel: '#jenkins-notification', color: '#FF0000', message: "${env.CONTAINER_NAME} CI / CD 파이프라인 구동 실패, 젠킨스 확인 해주세요")
error 'fail create secret file'
}
}
}
stage('create application-${env.PROFILE} properties by aws parameter store') {
steps {
dir('src/main/resources') {
withAWSParameterStore(credentialsId: 'aws-all-knu',
path: "/all-knu/properties/${env.PROFILE}",
naming: 'basename',
regionName: 'ap-northeast-2') {
writeFile file: "application-${env.PROFILE}.yml", text: "${env.BACKEND}"
}
}
}
post {
success {
echo 'success create secret file'
}
failure {
slackSend(channel: '#jenkins-notification', color: '#FF0000', message: "${env.CONTAINER_NAME} CI / CD 파이프라인 구동 실패, 젠킨스 확인 해주세요")
error 'fail create secret file'
}
}
}
stage('dockerizing by Dockerfile') {
steps {
sh '''
docker build -t $IMAGE_NAME .
'''
}
post {
success {
echo 'success dockerizing by Dockerfile'
}
failure {
slackSend(channel: '#jenkins-notification', color: '#FF0000', message: "${env.CONTAINER_NAME} CI / CD 파이프라인 구동 실패, 젠킨스 확인 해주세요")
error 'fail dockerizing by Dockerfile' // exit pipeline
}
}
}
stage('rm container') {
steps {
sh '''
docker rm -f $CONTAINER_NAME
'''
}
post {
success {
echo 'success rm container in pipeline'
}
failure {
slackSend(channel: '#jenkins-notification', color: '#FF0000', message: "${env.CONTAINER_NAME} CI / CD 파이프라인 구동 실패, 젠킨스 확인 해주세요")
error 'fail rm container in pipeline'
}
}
}
stage('deploy') {
steps {
sh 'docker run --name $CONTAINER_NAME -v $LOGGING_HOST_PATH:/var/log -e "SPRING_PROFILES_ACTIVE=$PROFILE" -e "TZ=$TIME_ZONE" --net $DOCKER_NETWORK -d -t $IMAGE_NAME'
}
post {
success {
slackSend(channel: '#jenkins-notification', color: '#00FF00', message: "${env.CONTAINER_NAME} CI / CD 파이프라인 구동 동작 성공")
echo 'success deploying all knu backend spring project'
}
failure {
slackSend(channel: '#jenkins-notification', color: '#FF0000', message: "${env.CONTAINER_NAME} CI / CD 파이프라인 구동 실패, 젠킨스 확인 해주세요")
error 'fail deploying all knu backend spring project' // exit pipeline
}
}
}
}
}