forked from ARM-software/CMSIS_5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
504 lines (466 loc) · 19.5 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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
@Library("cmsis")
import com.arm.dsg.cmsis.jenkins.ArtifactoryHelper
DOCKERINFO = [
'staging': [
'registryUrl': 'mcu--docker-staging.eu-west-1.artifactory.aws.arm.com',
'registryCredentialsId': 'artifactory',
'k8sPullSecret': 'artifactory-mcu-docker-staging',
'namespace': 'mcu--docker-staging',
'image': 'cmsis/linux',
'label': "${JENKINS_ENV}-${JOB_BASE_NAME}-${BUILD_NUMBER}"
],
'production': [
'registryUrl': 'mcu--docker.eu-west-1.artifactory.aws.arm.com',
'registryCredentialsId': 'artifactory',
'namespace': 'mcu--docker',
'k8sPullSecret': 'artifactory-mcu-docker',
'image': 'cmsis/linux',
'label': 'latest'
]
]
HADOLINT_VERSION = '2.6.0-alpine'
dockerinfo = DOCKERINFO['production']
isPrecommit = (JOB_BASE_NAME == 'pre_commit')
isPostcommit = (JOB_BASE_NAME == 'post_commit')
isNightly = (JOB_BASE_NAME == 'nightly')
isRelease = (JOB_BASE_NAME == 'release')
patternGlobal = [
'^Jenkinsfile'
]
patternDocker = [
'^docker/.*'
]
patternCoreM = [
'^CMSIS/Core/Include/.*',
'^Device/ARM/ARMCM.*'
]
patternCoreA = [
'^CMSIS/Core_A/Include/.*',
'^Device/ARM/ARMCA.*'
]
patternCoreValidation = [
'^CMSIS/CoreValidation/.*'
]
CONFIGURATIONS = [
'pre_commit': [
'mdevices': ['CM0', 'CM3', 'CM4FP', 'CM7DP', 'CM23', 'CM33NS', 'CM35PS', 'CM55NS'],
'adevices': ['CA7', 'CA9neon'],
'devices' : [],
'configs' : [
'AC5': ['low', 'tiny'],
'AC6': ['low', 'tiny'],
'AC6LTM': ['low', 'tiny'],
'GCC': ['low', 'tiny']
]
],
'post_commit': [
'devices' : ['CM0', 'CM0plus', 'CM3', 'CM4', 'CM4FP', 'CM7', 'CM7SP', 'CM7DP',
'CM23', 'CM23S', 'CM23NS', 'CM33', 'CM33S', 'CM33NS',
'CM35P', 'CM35PS', 'CM35PNS', 'CM55', 'CM55S', 'CM55NS',
'CA5', 'CA5neon', 'CA7', 'CA7neon', 'CA9', 'CA9neon'],
'configs' : [
'AC5': ['low', 'tiny'],
'AC6': ['low', 'tiny'],
'AC6LTM': ['low', 'tiny'],
'GCC': ['low', 'tiny']
]
],
'nightly': [
'devices' : ['CM0', 'CM0plus', 'CM3', 'CM4', 'CM4FP', 'CM7', 'CM7SP', 'CM7DP',
'CM23', 'CM23S', 'CM23NS', 'CM33', 'CM33S', 'CM33NS',
'CM35P', 'CM35PS', 'CM35PNS', 'CM55', 'CM55S', 'CM55NS',
'CA5', 'CA5neon', 'CA7', 'CA7neon', 'CA9', 'CA9neon'],
'configs' : [
'AC5': ['low', 'mid', 'high', 'size', 'tiny'],
'AC6': ['low', 'mid', 'high', 'size', 'tiny'],
'AC6LTM': ['low', 'mid', 'high', 'size', 'tiny'],
'GCC': ['low', 'mid', 'high', 'size', 'tiny']
]
],
'release': []
]
CONFIGURATION = CONFIGURATIONS[JOB_BASE_NAME]
// ---- PIPELINE CODE ----
def getChangeset() {
def fileset = sh encoding: 'UTF-8', label: '', returnStdout: true, script: 'git diff --name-only HEAD~1..HEAD'
return fileset.split('\n')
}
def fileSetMatches(fileset, patternset) {
return patternset.any { p ->
fileset.any{ f -> f ==~ p }
}
}
FORCE_BUILD = false
DOCKER_BUILD = isPrecommit || isPostcommit || isNightly
CORE_VALIDATION = isPrecommit || isPostcommit || isNightly
COMMIT = null
VERSION = null
artifactory = new ArtifactoryHelper(this)
pipeline {
agent { label 'master' }
options {
timestamps()
timeout(time: 1, unit: 'HOURS')
ansiColor('xterm')
skipDefaultCheckout()
}
environment {
CI_ACCOUNT = credentials('grasci')
ARTIFACTORY = credentials('artifactory')
USER = "${CI_ACCOUNT_USR}"
PASS = "${CI_ACCOUNT_PSW}"
ARTIFACTORY_API_KEY = "${ARTIFACTORY_PSW}"
}
stages {
stage('Checkout') {
steps {
script {
COMMIT = checkoutScmWithRetry(3)
echo "COMMIT: ${COMMIT}"
VERSION = (sh(returnStdout: true, script: 'git describe --always')).trim()
echo "VERSION: '${VERSION}'"
}
stash name: 'dockerfile', includes: 'docker/**'
}
}
stage('Analyse') {
when {
expression { return isPrecommit || isPostcommit }
beforeOptions true
}
steps {
script {
def fileset = changeset
def hasGlobal = fileSetMatches(fileset, patternGlobal)
def hasDocker = fileSetMatches(fileset, patternDocker)
def hasCoreM = fileSetMatches(fileset, patternCoreM)
def hasCoreA = fileSetMatches(fileset, patternCoreA)
def hasCoreValidation = fileSetMatches(fileset, patternCoreValidation)
echo """Change analysis:
- hasGlobal = ${hasGlobal}
- hasDocker = ${hasDocker}
- hasCoreM = ${hasCoreM}
- hasCoreA = ${hasCoreA}
- hasCoreValidation = ${hasCoreValidation}
"""
if (isPrecommit) {
if (hasGlobal || hasDocker || hasCoreM || hasCoreValidation) {
CONFIGURATION['devices'] += CONFIGURATION['mdevices']
}
if (hasGlobal || hasDocker || hasCoreA || hasCoreValidation) {
CONFIGURATION['devices'] += CONFIGURATION['adevices']
}
}
DOCKER_BUILD &= hasDocker
CORE_VALIDATION &= hasGlobal || hasDocker || hasCoreM || hasCoreA || hasCoreValidation
echo """Stage schedule:
- DOCKER_BUILD = ${DOCKER_BUILD}
- CORE_VALIDATION = ${CORE_VALIDATION}
"""
}
}
}
stage('Docker Lint') {
when {
expression { return DOCKER_BUILD }
beforeOptions true
}
agent {
kubernetes {
defaultContainer 'hadolint'
slaveConnectTimeout 600
yaml """\
apiVersion: v1
kind: Pod
securityContext:
runAsUser: 1000
runAsGroup: 1000
spec:
imagePullSecrets:
- name: artifactory-mcu-docker
securityContext:
runAsUser: 1000
runAsGroup: 1000
containers:
- name: hadolint
image: mcu--docker.eu-west-1.artifactory.aws.arm.com/hadolint/hadolint:${HADOLINT_VERSION}
alwaysPullImage: true
imagePullPolicy: Always
command:
- sleep
args:
- infinity
resources:
requests:
cpu: 2
memory: 2Gi
""".stripIndent()
}
}
steps {
unstash 'dockerfile'
sh 'hadolint --format json docker/dockerfile* | tee hadolint.log'
recordIssues tools: [hadoLint(id: 'hadolint', pattern: 'hadolint.log')],
qualityGates: [[threshold: 1, type: 'DELTA', unstable: true]],
referenceJobName: 'nightly', ignoreQualityGate: true
}
}
stage('Docker Build') {
when {
expression { return (isPrecommit || isPostcommit) && DOCKER_BUILD }
beforeOptions true
}
agent {
kubernetes {
defaultContainer 'docker-dind'
slaveConnectTimeout 600
yaml """\
apiVersion: v1
kind: Pod
spec:
imagePullSecrets:
- name: artifactory-mcu-docker
containers:
- name: docker-dind
image: docker:dind
securityContext:
privileged: true
volumeMounts:
- name: dind-storage
mountPath: /var/lib/docker
volumes:
- name: dind-storage
emptyDir: {}
""".stripIndent()
}
}
steps {
sh('apk add bash curl git')
script {
unstash 'dockerfile'
dir('docker') {
dockerinfo = DOCKERINFO['staging']
withCredentials([sshUserPrivateKey(credentialsId: 'grasci_with_pk',
keyFileVariable: 'grasciPk',
passphraseVariable: '',
usernameVariable: 'grasciUsername')]) {
sh("GIT_SSH_COMMAND='ssh -i $grasciPk -o StrictHostKeyChecking=no' ./getDependencies.sh")
}
docker.withRegistry("https://${dockerinfo['registryUrl']}", dockerinfo['registryCredentialsId']) {
def image = docker.build("${dockerinfo['registryUrl']}/${dockerinfo['image']}:${dockerinfo['label']}", "--build-arg DOCKER_REGISTRY=${dockerinfo['registryUrl']} .")
image.push()
}
}
}
}
}
stage('Pack') {
agent {
kubernetes {
defaultContainer 'cmsis'
slaveConnectTimeout 600
yaml """\
apiVersion: v1
kind: Pod
spec:
imagePullSecrets:
- name: ${dockerinfo['k8sPullSecret']}
securityContext:
runAsUser: 1000
runAsGroup: 1000
containers:
- name: cmsis
image: ${dockerinfo['registryUrl']}/${dockerinfo['image']}:${dockerinfo['label']}
alwaysPullImage: true
imagePullPolicy: Always
command:
- sleep
args:
- infinity
resources:
requests:
cpu: 2
memory: 2Gi
""".stripIndent()
}
}
steps {
checkoutScmWithRetry(3)
sh('./CMSIS/RTOS/RTX/LIB/fetch_libs.sh')
sh('./CMSIS/RTOS2/RTX/Library/fetch_libs.sh')
tee('doxygen.log') {
sh('./CMSIS/DoxyGen/gen_doc.sh')
}
sh('./CMSIS/Utilities/gen_pack.sh')
archiveArtifacts artifacts: 'output/ARM.CMSIS.*.pack', allowEmptyArchive: true
stash name: 'pack', includes: 'output/ARM.CMSIS.*.pack'
recordIssues tools: [doxygen(id: 'DOXYGEN', name: 'Doxygen', pattern: 'doxygen.log')],
qualityGates: [[threshold: 1, type: 'DELTA', unstable: true]],
referenceJobName: 'nightly', ignoreQualityGate: true
}
}
stage('CoreValidation') {
when {
expression { return CORE_VALIDATION }
beforeOptions true
}
matrix {
axes {
axis {
name 'DEVICE'
values 'CM0', 'CM0plus', 'CM3', 'CM4', 'CM4FP', 'CM7', 'CM7SP', 'CM7DP',
'CM23', 'CM23S', 'CM23NS', 'CM33', 'CM33S', 'CM33NS',
'CM35P', 'CM35PS', 'CM35PNS', 'CM55', 'CM55S', 'CM55NS',
'CA5', 'CA5neon', 'CA7', 'CA7neon', 'CA9', 'CA9neon'
}
}
stages {
stage('Test') {
when {
expression { return DEVICE in CONFIGURATION['devices'] }
beforeOptions true
}
agent {
kubernetes {
defaultContainer 'cmsis'
slaveConnectTimeout 600
yaml """\
apiVersion: v1
kind: Pod
spec:
imagePullSecrets:
- name: ${dockerinfo['k8sPullSecret']}
securityContext:
runAsUser: 1000
runAsGroup: 1000
containers:
- name: cmsis
image: ${dockerinfo['registryUrl']}/${dockerinfo['image']}:${dockerinfo['label']}
alwaysPullImage: true
imagePullPolicy: Always
command:
- sleep
args:
- infinity
resources:
requests:
cpu: 2
memory: 2Gi
""".stripIndent()
}
}
steps {
checkoutScmWithRetry(3)
dir('CMSIS/CoreValidation/Tests') {
script {
CONFIGURATION['configs'].each { COMPILER, OPTS ->
tee("CV_${COMPILER}_${DEVICE}.log") {
sh "python3 build.py -d ${DEVICE} -c ${COMPILER} -o ${OPTS.join(' -o ')} build run"
}
}
}
archiveArtifacts artifacts: 'CoreValidation_*.zip', allowEmptyArchive: true
stash name: "CV_${DEVICE}", includes: '*.log, *.junit'
}
}
}
}
}
}
stage('Results') {
when {
expression { return CORE_VALIDATION }
beforeOptions true
}
steps {
dir('results') {
deleteDir()
script {
CONFIGURATION['devices'].each { unstash "CV_${it}" }
}
recordIssues tools: [armCc(id: 'AC5', name: 'Arm Compiler 5', pattern: 'CV_AC5_*.log'),
clang(id: 'AC6', name: 'Arm Compiler 6', pattern: 'CV_AC6_*.log'),
clang(id: 'AC6LTM', name: 'Arm Compiler 6 LTM', pattern: 'CV_AC6LTM_*.log'),
gcc(id: 'GCC', name: 'GNU Compiler', pattern: 'CV_GCC_*.log')],
qualityGates: [[threshold: 1, type: 'DELTA', unstable: true]],
referenceJobName: 'nightly', ignoreQualityGate: true
xunit([
JUnit(pattern: 'corevalidation_*.junit', failIfNotNew: false, skipNoTestFiles: true)
])
}
}
}
stage('Docker Promote') {
when {
expression { return isPostcommit && DOCKER_BUILD }
beforeOptions true
}
agent {
kubernetes {
defaultContainer 'docker-dind'
slaveConnectTimeout 600
yaml """\
apiVersion: v1
kind: Pod
spec:
imagePullSecrets:
- name: artifactory-mcu-docker
containers:
- name: docker-dind
image: docker:dind
securityContext:
privileged: true
volumeMounts:
- name: dind-storage
mountPath: /var/lib/docker
volumes:
- name: dind-storage
emptyDir: {}
""".stripIndent()
}
}
steps {
script {
String postCommitTag = "${dockerinfo['registryUrl']}/${dockerinfo['image']}:${dockerinfo['label']}"
String prodCommitTag = "${DOCKERINFO['production']['registryUrl']}/${DOCKERINFO['production']['image']}:${DOCKERINFO['production']['label']}"
// Pull & retag Docker Staging Container to Production
docker.withRegistry("https://${dockerinfo['registryUrl']}", dockerinfo['registryCredentialsId']) {
def image = docker.image("$postCommitTag")
image.pull()
sh "docker tag $postCommitTag $prodCommitTag"
}
// Push to Docker Production
docker.withRegistry("https://${DOCKERINFO['production']['registryUrl']}", DOCKERINFO['production']['registryCredentialsId']) {
def image = docker.image("$prodCommitTag")
image.push()
}
}
}
}
stage('Release Promote') {
when {
expression { return isRelease }
beforeOptions true
}
steps {
unstash name: 'pack'
dir('output') {
script {
artifactory.upload pattern: 'ARM.CMSIS.*.pack',
target: "mcu.promoted/CMSIS_5/${VERSION}/",
props: "GIT_COMMIT=${COMMIT['GIT_COMMIT']}"
}
withCredentials([string(credentialsId: 'grasci_github', variable: 'ghtoken')]) {
sh """
curl -XPOST \
-H "Authorization:token ${ghtoken}" \
-H "Content-Type:application/octet-stream" \
--data-binary @ARM.CMSIS.${VERSION}.pack \
https://uploads.github.com/repos/ARM-software/CMSIS_5/releases/${VERSION}/assets?name=ARM.CMSIS.${VERSION}.pack
"""
}
}
}
}
}
}