-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
391 lines (383 loc) · 12.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
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
// SPDX-FileCopyrightText: 2023 Zextras <https://www.zextras.com>
//
// SPDX-License-Identifier: AGPL-3.0-only
pipeline {
parameters {
booleanParam defaultValue: false,
description: 'Whether to upload the packages in playground repository',
name: 'PLAYGROUND'
booleanParam defaultValue: false,
description: 'Whether to run the dependency check',
name: 'DEPENDENCY_CHECK'
}
options {
skipDefaultCheckout()
buildDiscarder(logRotator(numToKeepStr: '5'))
timeout(time: 1, unit: 'HOURS')
}
agent {
node {
label 'openjdk17-agent-v1'
}
}
environment {
NETWORK_OPTS = '--network ci_agent'
FAILURE_EMAIL_RECIPIENTS='[email protected]'
}
stages {
stage('Build setup') {
steps {
checkout([
$class: 'GitSCM',
branches: scm.branches,
extensions: [[
$class: 'CloneOption',
shallow: true,
depth: 2,
timeout: 30
]],
userRemoteConfigs: scm.userRemoteConfigs
])
withCredentials([file(credentialsId: 'jenkins-maven-settings.xml', variable: 'SETTINGS_PATH')]) {
sh 'cp $SETTINGS_PATH settings-jenkins.xml'
sh 'mvn -Dmaven.repo.local=$(pwd)/m2 -N wrapper:wrapper'
}
script {
env.GIT_COMMIT = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
}
}
}
stage('Compiling') {
steps {
sh 'mvn -T1C -B -q --settings settings-jenkins.xml compile'
}
post {
failure {
script {
if ("main".equals(BRANCH_NAME) || "devel".equals(BRANCH_NAME)) {
sendFailureEmail(STAGE_NAME)
}
}
}
}
}
stage('Testing') {
steps {
sh '''
mvn -B --settings settings-jenkins.xml \
-Dlogback.configurationFile="$(pwd)"/carbonio-ws-collaboration-boot/src/main/resources/logback-test-silent.xml \
verify
'''
recordCoverage(tools: [[pattern: 'target/site/jacoco-all-tests/jacoco.xml']])
}
post {
failure {
script {
if ("main".equals(BRANCH_NAME) || "devel".equals(BRANCH_NAME)) {
sendFailureEmail(STAGE_NAME)
}
}
}
}
}
stage('Dependency check') {
when {
expression { params.DEPENDENCY_CHECK == true }
}
steps {
dependencyCheck additionalArguments: '''
-o "./"
-s "./"
-f "HTML"
--prettyPrint''', odcInstallation: 'dependency-check'
}
}
stage('Sonarqube Analysis') {
steps {
withSonarQubeEnv(credentialsId: 'sonarqube-user-token', installationName: 'SonarQube instance') {
sh '''
mvn -Dsonar.dependencyCheck.htmlReportPath=./dependency-check-report.html \
-Dsonar.coverage.jacoco.xmlReportPaths=../target/site/jacoco-all-tests/jacoco.xml \
-B --settings settings-jenkins.xml sonar:sonar
'''
}
}
}
stage('Stashing for packaging') {
steps {
stash includes: '**', name: 'project'
}
}
stage('Building packages') {
parallel {
stage('Ubuntu') {
agent {
node {
label 'yap-agent-ubuntu-20.04-v2'
}
}
steps {
unstash 'project'
sh '''
mkdir /tmp/ws-collaboration
mv * /tmp/ws-collaboration
'''
script {
if (BRANCH_NAME == 'devel') {
def timestamp = new Date().format('yyyyMMddHHmmss')
sh "sudo yap build ubuntu /tmp/ws-collaboration -r ${timestamp}"
} else {
sh 'sudo yap build ubuntu /tmp/ws-collaboration'
}
}
stash includes: 'artifacts/', name: 'artifacts-ubuntu'
}
post {
failure {
script {
if ("main".equals(BRANCH_NAME) || "devel".equals(BRANCH_NAME)) {
sendFailureEmail(STAGE_NAME)
}
}
}
always {
archiveArtifacts artifacts: 'artifacts/*.deb', fingerprint: true
}
}
}
stage('RHEL') {
agent {
node {
label 'yap-agent-rocky-8-v2'
}
}
steps {
unstash 'project'
sh '''
mkdir /tmp/ws-collaboration
mv * /tmp/ws-collaboration
'''
script {
if (BRANCH_NAME == 'devel') {
def timestamp = new Date().format('yyyyMMddHHmmss')
sh "sudo yap build rocky /tmp/ws-collaboration -r ${timestamp}"
} else {
sh 'sudo yap build rocky /tmp/ws-collaboration'
}
}
stash includes: 'artifacts/x86_64/*.rpm', name: 'artifacts-rocky'
}
post {
failure {
script {
if ("main".equals(BRANCH_NAME) || "devel".equals(BRANCH_NAME)) {
sendFailureEmail(STAGE_NAME)
}
}
}
always {
archiveArtifacts artifacts: 'artifacts/x86_64/*.rpm', fingerprint: true
}
}
}
}
}
stage('Upload To Playground') {
when {
expression { params.PLAYGROUND == true }
}
steps {
unstash 'artifacts-ubuntu'
unstash 'artifacts-rocky'
script {
def server = Artifactory.server 'zextras-artifactory'
def buildInfo
def uploadSpec
buildInfo = Artifactory.newBuildInfo()
uploadSpec = """{
"files": [
{
"pattern": "artifacts/*.deb",
"target": "ubuntu-playground/pool/",
"props": "deb.distribution=focal;deb.distribution=jammy;deb.distribution=noble;deb.component=main;deb.architecture=amd64;vcs.revision=${env.GIT_COMMIT}"
},
{
"pattern": "artifacts/x86_64/(carbonio-ws-collaboration-ce)-(*).rpm",
"target": "centos8-playground/zextras/{1}/{1}-{2}.rpm",
"props": "rpm.metadata.arch=x86_64;rpm.metadata.vendor=zextras;vcs.revision=${env.GIT_COMMIT}"
},
{
"pattern": "artifacts/x86_64/(carbonio-ws-collaboration-ce)-(*).rpm",
"target": "rhel9-playground/zextras/{1}/{1}-{2}.rpm",
"props": "rpm.metadata.arch=x86_64;rpm.metadata.vendor=zextras;vcs.revision=${env.GIT_COMMIT}"
}
]
}"""
server.upload spec: uploadSpec, buildInfo: buildInfo, failNoOp: false
}
}
}
stage('Upload To Devel') {
when {
branch 'devel'
}
steps {
unstash 'artifacts-ubuntu'
unstash 'artifacts-rocky'
script {
def server = Artifactory.server 'zextras-artifactory'
def buildInfo
def uploadSpec
buildInfo = Artifactory.newBuildInfo()
uploadSpec = """{
"files": [
{
"pattern": "artifacts/*.deb",
"target": "ubuntu-devel/pool/",
"props": "deb.distribution=focal;deb.distribution=jammy;deb.distribution=noble;deb.component=main;deb.architecture=amd64;vcs.revision=${env.GIT_COMMIT}"
},
{
"pattern": "artifacts/x86_64/(carbonio-ws-collaboration-ce)-(*).rpm",
"target": "centos8-devel/zextras/{1}/{1}-{2}.rpm",
"props": "rpm.metadata.arch=x86_64;rpm.metadata.vendor=zextras;vcs.revision=${env.GIT_COMMIT}"
},
{
"pattern": "artifacts/x86_64/(carbonio-ws-collaboration-ce)-(*).rpm",
"target": "rhel9-devel/zextras/{1}/{1}-{2}.rpm",
"props": "rpm.metadata.arch=x86_64;rpm.metadata.vendor=zextras;vcs.revision=${env.GIT_COMMIT}"
}
]
}"""
server.upload spec: uploadSpec, buildInfo: buildInfo, failNoOp: false
}
}
post {
failure {
script {
sendFailureEmail(STAGE_NAME)
}
}
}
}
stage('Upload & Promotion Config') {
when {
buildingTag()
}
steps {
unstash 'artifacts-ubuntu'
unstash 'artifacts-rocky'
script {
def server = Artifactory.server 'zextras-artifactory'
def buildInfo
def uploadSpec
def config
//ubuntu
buildInfo = Artifactory.newBuildInfo()
buildInfo.name += '-ubuntu'
uploadSpec = """{
"files": [
{
"pattern": "artifacts/*.deb",
"target": "ubuntu-rc/pool/",
"props": "deb.distribution=focal;deb.distribution=jammy;deb.distribution=noble;deb.component=main;deb.architecture=amd64;vcs.revision=${env.GIT_COMMIT}"
}
]
}"""
server.upload spec: uploadSpec, buildInfo: buildInfo, failNoOp: false
config = [
'buildName' : buildInfo.name,
'buildNumber' : buildInfo.number,
'sourceRepo' : 'ubuntu-rc',
'targetRepo' : 'ubuntu-release',
'comment' : 'Do not change anything! Just press the button',
'status' : 'Released',
'includeDependencies': false,
'copy' : true,
'failFast' : true
]
Artifactory.addInteractivePromotion server: server,
promotionConfig: config,
displayName: 'Ubuntu Promotion to Release'
server.publishBuildInfo buildInfo
//rhel8
buildInfo = Artifactory.newBuildInfo()
buildInfo.name += "-centos8"
uploadSpec = """{
"files": [
{
"pattern": "artifacts/x86_64/(carbonio-ws-collaboration-ce)-(*).rpm",
"target": "centos8-rc/zextras/{1}/{1}-{2}.rpm",
"props": "rpm.metadata.arch=x86_64;rpm.metadata.vendor=zextras;vcs.revision=${env.GIT_COMMIT}"
}
]
}"""
server.upload spec: uploadSpec, buildInfo: buildInfo, failNoOp: false
config = [
'buildName' : buildInfo.name,
'buildNumber' : buildInfo.number,
'sourceRepo' : 'centos8-rc',
'targetRepo' : 'centos8-release',
'comment' : 'Do not change anything! Just press the button',
'status' : 'Released',
'includeDependencies': false,
'copy' : true,
'failFast' : true
]
Artifactory.addInteractivePromotion server: server,
promotionConfig: config,
displayName: 'RHEL8 Promotion to Release'
server.publishBuildInfo buildInfo
//rhel9
buildInfo = Artifactory.newBuildInfo()
buildInfo.name += "-rhel9"
uploadSpec = """{
"files": [
{
"pattern": "artifacts/x86_64/(carbonio-ws-collaboration-ce)-(*).rpm",
"target": "rhel9-rc/zextras/{1}/{1}-{2}.rpm",
"props": "rpm.metadata.arch=x86_64;rpm.metadata.vendor=zextras;vcs.revision=${env.GIT_COMMIT}"
}
]
}"""
server.upload spec: uploadSpec, buildInfo: buildInfo, failNoOp: false
config = [
'buildName' : buildInfo.name,
'buildNumber' : buildInfo.number,
'sourceRepo' : 'rhel9-rc',
'targetRepo' : 'rhel9-release',
'comment' : 'Do not change anything! Just press the button',
'status' : 'Released',
'includeDependencies': false,
'copy' : true,
'failFast' : true
]
Artifactory.addInteractivePromotion server: server,
promotionConfig: config,
displayName: 'RHEL9 Promotion to Release'
server.publishBuildInfo buildInfo
}
}
post {
failure {
script {
sendFailureEmail(STAGE_NAME)
}
}
}
}
}
}
void sendFailureEmail(String step) {
def commitInfo =sh(
script: 'git log -1 --pretty=tformat:\'<ul><li>Revision: %H</li><li>Title: %s</li><li>Author: %ae</li></ul>\'',
returnStdout: true
)
emailext body: """\
<b>${step.capitalize()}</b> step has failed on trunk.<br /><br />
Last commit info: <br />
${commitInfo}<br /><br />
Check the failing build at the <a href=\"${BUILD_URL}\">following link</a><br />
""",
subject: "[WORKSTREAM COLLABORATION TRUNK FAILURE] Trunk ${step} step failure",
to: FAILURE_EMAIL_RECIPIENTS
}