-
Notifications
You must be signed in to change notification settings - Fork 22
/
Jenkinsfile
443 lines (424 loc) · 21.7 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
#!groovy
pipeline {
agent {
node {
label params.label == "" ? "metersphere" : params.label
}
}
options {
checkoutToSubdirectory('installer')
}
environment {
IMAGE_PREFIX = "registry.fit2cloud.com/metersphere"
}
stages {
stage('Preparation') {
steps {
script {
if (params.branch != null) {
env.BRANCH_NAME = params.branch
}
if (params.release != null) {
env.RELEASE = params.release.replace("-arm64", "")
} else {
env.RELEASE = env.BRANCH_NAME
}
echo "RELEASE=${RELEASE}"
echo "BRANCH=${BRANCH_NAME}"
}
}
}
stage('Checkout') {
when { tag pattern: "^v.*?(?<!-arm64)\$", comparator: "REGEXP" }
steps {
// Get some code from a GitHub repository
dir('metersphere') {
git credentialsId:'metersphere-registry', url: '[email protected]:metersphere/metersphere.git', branch: "${BRANCH_NAME}"
}
dir('metersphere-xpack') {
git credentialsId:'metersphere-registry', url: '[email protected]:metersphere/metersphere-xpack.git', branch: "${BRANCH_NAME}"
}
dir('task-runner') {
git credentialsId:'metersphere-registry', url: '[email protected]:metersphere/task-runner.git', branch: "${BRANCH_NAME}"
}
dir('result-hub') {
git credentialsId:'metersphere-registry', url: '[email protected]:metersphere/result-hub.git', branch: "${BRANCH_NAME}"
}
dir('metersphere-standalone') {
git credentialsId:'metersphere-registry', url: '[email protected]:metersphere/metersphere-standalone.git', branch: "${BRANCH_NAME}"
}
dir('jenkins-plugin') {
git credentialsId:'metersphere-registry', url: '[email protected]:metersphere/jenkins-plugin.git', branch: "${BRANCH_NAME}"
}
sh '''
git config --global user.email "[email protected]"
git config --global user.name "metersphere-bot"
'''
}
}
stage('Tags All repo') {
when { tag pattern: "^v.*?(?<!-arm64)\$", comparator: "REGEXP" }
steps {
dir('metersphere') {
sh("git tag -f -a ${RELEASE} -m 'Tagged by Jenkins'")
sh("git push -f origin refs/tags/${RELEASE}")
}
dir('metersphere-xpack') {
sh("git tag -f -a ${RELEASE} -m 'Tagged by Jenkins'")
sh("git push -f origin refs/tags/${RELEASE}")
}
dir('task-runner') {
sh("git tag -f -a ${RELEASE} -m 'Tagged by Jenkins'")
sh("git push -f origin refs/tags/${RELEASE}")
}
dir('result-hub') {
sh("git tag -f -a ${RELEASE} -m 'Tagged by Jenkins'")
sh("git push -f origin refs/tags/${RELEASE}")
}
dir('jenkins-plugin') {
sh("git tag -f -a ${RELEASE} -m 'Tagged by Jenkins'")
sh("git push -f origin refs/tags/${RELEASE}")
}
dir('metersphere-standalone') {
sh("git tag -f -a ${RELEASE} -m 'Tagged by Jenkins'")
sh("git push -f origin refs/tags/${RELEASE}")
}
build job:"/刷新组织最新分支"
}
}
stage('Build SDK') {
when { tag pattern: "^v.*?(?<!-arm64)\$", comparator: "REGEXP" }
steps {
script {
REVISION = ""
if (env.RELEASE.startsWith("v") ) {
REVISION = env.RELEASE.substring(1)
} else {
REVISION = env.RELEASE
}
env.REVISION = "${REVISION}"
echo "REVISION=${REVISION}"
}
script {
for (int i=0;i<10;i++) {
try {
echo "Waiting for scanning new created Job"
sleep 10
build job:"../metersphere/${RELEASE}", quietPeriod:10, parameters: [
string(name: 'buildSdk', value: "true"),
]
break
} catch (Exception e) {
println(e)
println("Not building the job ../metersphere/${RELEASE} as it doesn't exist")
continue
}
}
}
}
}
stage('Build Repos') {
when { tag pattern: "^v.*?(?<!-arm64)\$", comparator: "REGEXP" }
parallel {
stage('metersphere-xpack') {
steps {
script {
for (int i=0;i<10;i++) {
try {
echo "Waiting for scanning new created Job"
sleep 10
build job:"../metersphere-xpack/${RELEASE}", quietPeriod:10
break
} catch (Exception e) {
println("Not building the job ../metersphere-xpack/${RELEASE} as it doesn't exist")
continue
}
}
}
}
}
stage('task-runner') {
steps {
script {
for (int i=0;i<10;i++) {
try {
echo "Waiting for scanning new created Job"
sleep 10
build job:"../task-runner/${RELEASE}", quietPeriod:10
break
} catch (Exception e) {
println("Not building the job ../task-runner/${RELEASE} as it doesn't exist")
continue
}
}
}
}
}
stage('result-hub') {
steps {
script {
for (int i=0;i<10;i++) {
try {
echo "Waiting for scanning new created Job"
sleep 10
build job:"../result-hub/${RELEASE}", quietPeriod:10
break
} catch (Exception e) {
println("Not building the job ../result-hub/${RELEASE} as it doesn't exist")
continue
}
}
}
}
}
stage('jenkins-plugin') {
steps {
script {
for (int i=0;i<10;i++) {
try {
echo "Waiting for scanning new created Job"
sleep 10
build job:"../jenkins-plugin/${RELEASE}", quietPeriod:10
break
} catch (Exception e) {
println("Not building the job ../jenkins-plugin/${RELEASE} as it doesn't exist")
continue
}
}
}
}
}
}
}
stage('metersphere') {
when { tag pattern: "^v.*?(?<!-arm64)\$", comparator: "REGEXP" }
steps {
script {
for (int i=0;i<10;i++) {
try {
echo "Waiting for scanning new created Job"
sleep 10
build job:"../metersphere/${RELEASE}", quietPeriod:10
break
} catch (Exception e) {
println(e)
println("Not building the job ../metersphere/${RELEASE} as it doesn't exist")
continue
}
}
}
}
}
stage('metersphere-standalone') {
when { tag pattern: "^v.*?(?<!-arm64)\$", comparator: "REGEXP" }
steps {
script {
for (int i=0;i<10;i++) {
try {
echo "Waiting for scanning new created Job"
sleep 10
build job:"../metersphere-standalone/${RELEASE}", quietPeriod:10
break
} catch (Exception e) {
println(e)
println("Not building the job ../metersphere-standalone/${RELEASE} as it doesn't exist")
continue
}
}
}
}
}
stage('Modify install conf') {
when {
anyOf {
tag pattern: "^v.*", comparator: "REGEXP"
}
}
steps {
dir('installer') {
sh '''
rm -rf metersphere-*.tar.gz
#修改安装参数
sed -i -e "s#MS_IMAGE_TAG=.*#MS_IMAGE_TAG=${RELEASE}#g" install.conf
sed -i -e "s#MS_IMAGE_PREFIX=.*#MS_IMAGE_PREFIX=${IMAGE_PREFIX}#g" install.conf
echo ${RELEASE} > ./metersphere/version
'''
}
}
}
stage('Package Online-install') {
when {
anyOf {
tag pattern: "^v.*?(?<!-arm64)\$", comparator: "REGEXP";
}
}
steps {
dir('installer') {
sh '''
#打包社区版在线包
touch metersphere-ce-online-installer-${RELEASE}.tar.gz
tar --transform "s/^\\./metersphere-ce-online-installer-${RELEASE}/" \\
--exclude metersphere-ce-online-installer-${RELEASE}.tar.gz \\
--exclude metersphere-ce-offline-installer-${RELEASE}.tar.gz \\
--exclude metersphere-ce-release-${RELEASE}.tar.gz \\
--exclude .git \\
--exclude images \\
--exclude community \\
--exclude enterprise \\
--exclude docker \\
-czvf metersphere-ce-online-installer-${RELEASE}.tar.gz .
'''
}
}
}
stage('Release') {
when { tag pattern: "^v.*?(?<!-arm64)\$", comparator: "REGEXP" }
steps {
withCredentials([string(credentialsId: 'gitrelease', variable: 'TOKEN'), string(credentialsId: 'HTTPS_PROXY', variable: 'HTTPS_PROXY')]) {
withEnv(["TOKEN=$TOKEN", "HTTPS_PROXY=$HTTPS_PROXY"]) {
dir('installer') {
sh script: '''
release=$(curl -XPOST -H "Authorization:token $TOKEN" --data "{\\"tag_name\\": \\"${RELEASE}\\", \\"target_commitish\\": \\"${BRANCH_NAME}\\", \\"name\\": \\"${RELEASE}\\", \\"body\\": \\"\\", \\"draft\\": false, \\"prerelease\\": true}" https://api.github.com/repos/metersphere/metersphere/releases)
id=$(echo "$release" | sed -n -e \'s/"id":\\ \\([0-9]\\+\\),/\\1/p\' | head -n 1 | sed \'s/[[:blank:]]//g\')
curl -XPOST -H "Authorization:token $TOKEN" -H "Content-Type:application/octet-stream" --data-binary @metersphere-ce-online-installer-${RELEASE}.tar.gz https://uploads.github.com/repos/metersphere/metersphere/releases/${id}/assets?name=metersphere-ce-online-installer-${RELEASE}.tar.gz
ossutil -c /opt/jenkins-home/metersphere/config cp -f metersphere-ce-online-installer-${RELEASE}.tar.gz oss://resource-fit2cloud-com/metersphere/metersphere/releases/download/${RELEASE}/ --update
curl -XPOST -H "Authorization:token $TOKEN" --data "{\\"tag_name\\": \\"${RELEASE}\\", \\"target_commitish\\": \\"${BRANCH_NAME}\\", \\"name\\": \\"${RELEASE}\\", \\"body\\": \\"\\", \\"draft\\": false, \\"prerelease\\": true}" https://api.github.com/repos/metersphere/metersphere-standalone/releases
'''
}
}
}
}
}
stage('Package Offline-install') {
when { tag pattern: "^v.*", comparator: "REGEXP" }
steps {
dir('installer') {
script {
def images = ['mysql:8.0.38',
'kafka:3.7.1',
'redis:7.2.6-alpine',
'minio:RELEASE.2024-05-07T06-41-25Z',
"metersphere-ce:${RELEASE}",
"metersphere-ee:${RELEASE}"
]
for (image in images) {
waitUntil {
def r = sh script: "docker pull ${IMAGE_PREFIX}/${image}", returnStatus: true
r == 0;
}
}
}
sh '''
#保存社区版镜像
rm -rf images && mkdir images && cd images
docker save ${IMAGE_PREFIX}/metersphere-ce:${RELEASE} \\
${IMAGE_PREFIX}/kafka:3.7.1 \\
${IMAGE_PREFIX}/mysql:8.0.38 \\
${IMAGE_PREFIX}/redis:7.2.6-alpine \\
${IMAGE_PREFIX}/minio:RELEASE.2024-05-07T06-41-25Z > metersphere.tar
cd ..
#保存企业版镜像
rm -rf enterprise && mkdir enterprise && cd enterprise
docker save ${IMAGE_PREFIX}/metersphere-ee:${RELEASE} \\
${IMAGE_PREFIX}/kafka:3.7.1 \\
${IMAGE_PREFIX}/mysql:8.0.38 \\
${IMAGE_PREFIX}/redis:7.2.6-alpine \\
${IMAGE_PREFIX}/minio:RELEASE.2024-05-07T06-41-25Z > metersphere.tar
cd ..
'''
script {
// 区分不同架构
RELEASE = ""
ARCH = "x86_64"
if (env.TAG_NAME != null) {
RELEASE = env.TAG_NAME
if (RELEASE.endsWith("-arm64")) {
ARCH = "aarch64"
}
} else {
RELEASE = env.BRANCH_NAME
}
env.RELEASE = "${RELEASE}"
env.ARCH = "${ARCH}"
echo "RELEASE=${RELEASE}"
echo "ARCH=${ARCH}"
}
sh '''
#获取docker
rm -rf docker/*
rm -rf docker
wget https://resource.fit2cloud.com/docker/download/${ARCH}/docker-25.0.2.tgz
wget https://resource.fit2cloud.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-${ARCH} && mv docker-compose-linux-${ARCH} docker-compose && chmod +x docker-compose
tar -zxvf docker-25.0.2.tgz
rm -rf docker-25.0.2.tgz
mv docker bin && mkdir docker && mv bin docker/
mv docker-compose docker/bin
mkdir docker/service && mv docker.service docker/service/
#打包社区版离线包
touch metersphere-ce-offline-installer-${RELEASE}.tar.gz
tar --transform "s/^\\./metersphere-ce-offline-installer-${RELEASE}/" \\
--exclude metersphere-ce-online-installer-${RELEASE}.tar.gz \\
--exclude metersphere-ce-offline-installer-${RELEASE}.tar.gz \\
--exclude metersphere-ce-release-${RELEASE}.tar.gz \\
--exclude .git \\
--exclude enterprise \\
-czvf metersphere-ce-offline-installer-${RELEASE}.tar.gz .
md5sum -b metersphere-ce-offline-installer-${RELEASE}.tar.gz | awk '{print $1}' > metersphere-ce-offline-installer-${RELEASE}.tar.gz.md5
rm -rf images
mv enterprise images
#打包企业版离线包
sed -i -e "s#-ce#-ee#g" metersphere/docker-compose-metersphere.yml
sed -i -e "s#-ce#-ee#g" metersphere/docker-compose-task-runner.yml
sed -i -e "s#-ce#-ee#g" metersphere/docker-compose-result-hub.yml
# 部分配置只有企业版包有
echo '# 企业版配置' >> install.conf
echo 'MS_ENTERPRISE_ENABLE=true' >> install.conf
rm -rf metersphere/*.yml-e
touch metersphere-ee-offline-installer-${RELEASE}.tar.gz
tar --transform "s/^\\./metersphere-ee-offline-installer-${RELEASE}/" \\
--exclude metersphere-ee-offline-installer-${RELEASE}.tar.gz \\
--exclude metersphere-ce-online-installer-${RELEASE}.tar.gz \\
--exclude metersphere-ce-offline-installer-${RELEASE}.tar.gz \\
--exclude metersphere-ce-offline-installer-${RELEASE}.tar.gz.md5 \\
--exclude .git \\
-czvf metersphere-ee-offline-installer-${RELEASE}.tar.gz .
md5sum -b metersphere-ee-offline-installer-${RELEASE}.tar.gz | awk '{print $1}' > metersphere-ee-offline-installer-${RELEASE}.tar.gz.md5
rm -rf images
'''
}
}
}
stage('Upload') {
when {
anyOf {
tag pattern: "^v\\d+\\.\\d+\\.\\d+-alpha\$", comparator: "REGEXP";
tag pattern: "^v\\d+\\.\\d+\\.\\d+-alpha-arm64\$", comparator: "REGEXP";
tag pattern: "^v\\d+\\.\\d+\\.\\d+-beta\$", comparator: "REGEXP";
tag pattern: "^v\\d+\\.\\d+\\.\\d+-beta-arm64\$", comparator: "REGEXP";
tag pattern: "^v\\d+\\.\\d+\\.\\d+\$", comparator: "REGEXP";
tag pattern: "^v\\d+\\.\\d+\\.\\d+-arm64\$", comparator: "REGEXP";
tag pattern: "^v\\d+\\.\\d+\\.\\d+-lts\$", comparator: "REGEXP";
tag pattern: "^v\\d+\\.\\d+\\.\\d+-lts-arm64\$", comparator: "REGEXP"
}
}
steps {
dir('installer') {
echo "UPLOADING"
withCredentials([usernamePassword(credentialsId: 'OSSKEY', passwordVariable: 'SK', usernameVariable: 'AK')]) {
sh("java -jar /opt/uploadToOss.jar $AK $SK fit2cloud2-offline-installer metersphere/release/metersphere-ce-offline-installer-${RELEASE}.tar.gz ./metersphere-ce-offline-installer-${RELEASE}.tar.gz")
sh("java -jar /opt/uploadToOss.jar $AK $SK fit2cloud2-offline-installer metersphere/release/metersphere-ce-offline-installer-${RELEASE}.tar.gz.md5 ./metersphere-ce-offline-installer-${RELEASE}.tar.gz.md5")
sh("java -jar /opt/uploadToOss.jar $AK $SK fit2cloud2-offline-installer metersphere/release/metersphere-ee-offline-installer-${RELEASE}.tar.gz ./metersphere-ee-offline-installer-${RELEASE}.tar.gz")
sh("java -jar /opt/uploadToOss.jar $AK $SK fit2cloud2-offline-installer metersphere/release/metersphere-ee-offline-installer-${RELEASE}.tar.gz.md5 ./metersphere-ee-offline-installer-${RELEASE}.tar.gz.md5")
}
}
}
}
}
post('Notification') {
always {
withCredentials([string(credentialsId: 'wechat-bot-webhook', variable: 'WEBHOOK')]) {
qyWechatNotification failNotify: true, mentionedId: '', mentionedMobile: '', webhookUrl: "$WEBHOOK"
}
}
}
}