-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
208 lines (203 loc) · 11.9 KB
/
Jenkinsfile
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
pipeline {
agent any
tools {
nodejs "nodejs"
}
stages {
stage('Project Build') {
steps {
script {
if(env.BRANCH_NAME == 'dev-front') {
echo "Front Project Build Step"
} else if(env.BRANCH_NAME == 'feature-back/auth-server') {
echo "Auth Server Project Build Step"
dir('Backend/AuthServer') {
sh 'chmod +x gradlew'
sh './gradlew clean build -x test'
}
} else if(env.BRANCH_NAME == 'feature-back/member') {
echo "ConstelinkMember Project Build Step"
dir('Backend/ConstelinkMember') {
sh 'chmod +x gradlew'
sh './gradlew clean build -x test'
}
} else if(env.BRANCH_NAME == 'feature-back/beneficiary') {
echo "ConstelinkBeneficiary Project Build Step"
dir('Backend/ConstelinkBeneficiary') {
sh 'chmod +x gradlew'
sh './gradlew clean build -x test'
}
} else if(env.BRANCH_NAME == 'feature-back/fundraising') {
echo "ConstelinkFundraising Project Build Step"
dir('Backend/ConstelinkFundraising') {
sh 'chmod +x gradlew'
sh './gradlew clean build -x test'
}
} else if(env.BRANCH_NAME == 'feature-back/file') {
echo "ConstelinkFile Project Build Step"
dir('Backend/ConstelinkFile') {
sh 'chmod +x gradlew'
sh './gradlew clean build -x test'
}
} else if(env.BRANCH_NAME == 'feature-back/notice') {
echo "ConstelinkNotice Project Build Step"
dir('Backend/ConstelinkNotice') {
sh 'chmod +x gradlew'
sh './gradlew clean build -x test'
}
}
}
}
}
stage('Image Build') {
environment {
PATH = "/busybox:/kaniko:$PATH"
}
steps {
script {
podTemplate(yaml: """
kind: Pod
metadata:
name: kaniko
spec:
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
imagePullPolicy: Always
command:
- sleep
args:
- 99d
volumeMounts:
- name: shared-workspace
mountPath: /workspace
- name: docker-config
mountPath: /kaniko/.docker
tty: true
nodeSelector:
node-role.kubernetes.io/control-plane: ""
volumes:
- name: shared-workspace
hostPath:
path: ${WORKSPACE}
type: Directory
- name: docker-config
secret:
secretName: regcred
items:
- key: .dockerconfigjson
path: config.json
""") {
node(POD_LABEL) {
container(name: 'kaniko', shell: '/busybox/sh') {
if(env.BRANCH_NAME == 'dev-front') {
echo "Front Image Build Step"
sh """#!/busybox/sh
/kaniko/executor --context=/workspace/Frontend --dockerfile=/workspace/Frontend/Dockerfile --destination=sadoruin/constelink-front:${env.BUILD_NUMBER}
"""
} else if(env.BRANCH_NAME == 'feature-back/auth-server') {
echo "Auth Server Image Build Step"
sh """#!/busybox/sh
/kaniko/executor --context=/workspace/Backend/AuthServer --dockerfile=/workspace/Backend/AuthServer/Dockerfile --destination=sadoruin/constelink-authserver:${env.BUILD_NUMBER}
"""
} else if(env.BRANCH_NAME == 'feature-back/member') {
echo "ConstelinkMember Image Build Step"
sh """#!/busybox/sh
/kaniko/executor --context=/workspace/Backend/ConstelinkMember --dockerfile=/workspace/Backend/ConstelinkMember/Dockerfile --destination=sadoruin/constelink-member:${env.BUILD_NUMBER}
"""
} else if(env.BRANCH_NAME == 'feature-back/beneficiary') {
echo "ConstelinkBeneficiary Image Build Step"
sh """#!/busybox/sh
/kaniko/executor --context=/workspace/Backend/ConstelinkBeneficiary --dockerfile=/workspace/Backend/ConstelinkBeneficiary/Dockerfile --destination=sadoruin/constelink-beneficiary:${env.BUILD_NUMBER}
"""
} else if(env.BRANCH_NAME == 'feature-back/fundraising') {
echo "ConstelinkFundraising Image Build Step"
sh """#!/busybox/sh
/kaniko/executor --context=/workspace/Backend/ConstelinkFundraising --dockerfile=/workspace/Backend/ConstelinkFundraising/Dockerfile --destination=sadoruin/constelink-fundraising:${env.BUILD_NUMBER}
"""
} else if(env.BRANCH_NAME == 'feature-back/file') {
echo "ConstelinkFile Image Build Step"
sh """#!/busybox/sh
/kaniko/executor --context=/workspace/Backend/ConstelinkFile --dockerfile=/workspace/Backend/ConstelinkFile/Dockerfile --destination=sadoruin/constelink-file:${env.BUILD_NUMBER}
"""
} else if(env.BRANCH_NAME == 'feature-back/notice') {
echo "ConstelinkNotice Image Build Step"
sh """#!/busybox/sh
/kaniko/executor --context=/workspace/Backend/ConstelinkNotice --dockerfile=/workspace/Backend/ConstelinkNotice/Dockerfile --destination=sadoruin/constelink-notice:${env.BUILD_NUMBER}
"""
}
}
}
}
}
}
}
stage('Deploy') {
steps {
script {
dir('/git') {
git branch: 'main',
credentialsId: 'gitlab-account',
url: 'https://lab.ssafy.com/dope2514/s08p22a206-manifest'
sh 'git config --global user.email "[email protected]"'
sh 'git config --global user.name "SadoRuin"'
if(env.BRANCH_NAME == 'dev-front') {
echo "Front Deploy Step"
sh """
sed -i 's/constelink-front:\\([^:]*\\)/constelink-front:${env.BUILD_NUMBER}/g' manifests/constelink-front.yaml
git add manifests/constelink-front.yaml
git commit -m 'Update constelink-front tag to ${env.BUILD_NUMBER}'
"""
} else if(env.BRANCH_NAME == 'feature-back/auth-server') {
echo "Auth Server Deploy Step"
sh """
sed -i 's/constelink-authserver:\\([^:]*\\)/constelink-authserver:${env.BUILD_NUMBER}/g' manifests/constelink-authserver.yaml
git add manifests/constelink-authserver.yaml
git commit -m 'Update constelink-authserver tag to ${env.BUILD_NUMBER}'
"""
} else if(env.BRANCH_NAME == 'feature-back/member') {
echo "ConstelinkMember Deploy Step"
sh """
sed -i 's/constelink-member:\\([^:]*\\)/constelink-member:${env.BUILD_NUMBER}/g' manifests/constelink-member.yaml
git add manifests/constelink-member.yaml
git commit -m 'Update constelink-member tag to ${env.BUILD_NUMBER}'
"""
} else if(env.BRANCH_NAME == 'feature-back/beneficiary') {
echo "ConstelinkBeneficiary Deploy Step"
sh """
sed -i 's/constelink-beneficiary:\\([^:]*\\)/constelink-beneficiary:${env.BUILD_NUMBER}/g' manifests/constelink-beneficiary.yaml
git add manifests/constelink-beneficiary.yaml
git commit -m 'Update constelink-beneficiary tag to ${env.BUILD_NUMBER}'
"""
} else if(env.BRANCH_NAME == 'feature-back/fundraising') {
echo "ConstelinkFundraising Deploy Step"
sh """
sed -i 's/constelink-fundraising:\\([^:]*\\)/constelink-fundraising:${env.BUILD_NUMBER}/g' manifests/constelink-fundraising.yaml
git add manifests/constelink-fundraising.yaml
git commit -m 'Update constelink-fundraising tag to ${env.BUILD_NUMBER}'
"""
} else if(env.BRANCH_NAME == 'feature-back/file') {
echo "ConstelinkFile Deploy Step"
sh """
sed -i 's/constelink-file:\\([^:]*\\)/constelink-file:${env.BUILD_NUMBER}/g' manifests/constelink-file.yaml
git add manifests/constelink-file.yaml
git commit -m 'Update constelink-file tag to ${env.BUILD_NUMBER}'
"""
} else if(env.BRANCH_NAME == 'feature-back/notice') {
echo "ConstelinkNotice Deploy Step"
sh """
sed -i 's/constelink-notice:\\([^:]*\\)/constelink-notice:${env.BUILD_NUMBER}/g' manifests/constelink-notice.yaml
git add manifests/constelink-notice.yaml
git commit -m 'Update constelink-notice tag to ${env.BUILD_NUMBER}'
"""
}
withCredentials([usernamePassword(credentialsId: 'gitlab-account', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh 'git remote set-url origin https://$GIT_USERNAME:[email protected]/dope2514/s08p22a206-manifest.git'
sh 'git push origin main'
}
}
}
}
}
}
}