forked from nrfconnect/sdk-zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
354 lines (320 loc) · 14.3 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
//
// Copyright (c) 2020 Nordic Semiconductor ASA. All Rights Reserved.
//
// The information contained herein is confidential property of Nordic Semiconductor ASA.
// The use, copying, transfer or disclosure of such information is prohibited except by
// express written agreement with Nordic Semiconductor ASA.
//
@Library("CI_LIB") _
HashMap CI_STATE = lib_State.getConfig(JOB_NAME)
def TestExecutionList = [:]
properties([
pipelineTriggers([
parameterizedCron( [
((JOB_NAME =~ /latest\/night\/.*\/master/).find() ? CI_STATE.CFG.CRON.NIGHTLY : ''),
((JOB_NAME =~ /latest\/week\/.*\/master/).find() ? CI_STATE.CFG.CRON.WEEKLY : '')
].join(' \n') )
]),
( JOB_NAME.contains('sub/') ? disableResume() : disableConcurrentBuilds() )
])
pipeline {
parameters {
booleanParam(name: 'RUN_DOWNSTREAM', description: 'if false skip downstream jobs', defaultValue: false)
booleanParam(name: 'RUN_TESTS', description: 'if false skip testing', defaultValue: true)
booleanParam(name: 'RUN_BUILD', description: 'if false skip building', defaultValue: true)
booleanParam(name: 'RUN_BUILD_UPSTREAM', description: 'if false skip building', defaultValue: true)
string(name: 'SANITYCHECK_RETRY_NUM', description: 'Default number of sanitycheck retries', defaultValue: '7')
string(name: 'PLATFORMS', description: 'Default Platforms to test', defaultValue: 'nrf9160dk_nrf9160 nrf9160dk_nrf9160ns nrf52dk_nrf52832 nrf52840dk_nrf52840')
string(name: 'jsonstr_CI_STATE', description: 'Default State if no upstream job', defaultValue: CI_STATE.CFG.INPUT_STATE_STR)
choice(name: 'CRON', choices: ['COMMIT', 'NIGHTLY', 'WEEKLY'], description: 'Cron Test Phase')
}
agent { label CI_STATE.CFG.AGENT_LABELS }
options {
// Checkout the repository to this folder instead of root
checkoutToSubdirectory('zephyr')
parallelsAlwaysFailFast()
timeout(time: CI_STATE.CFG.TIMEOUT.time, unit: CI_STATE.CFG.TIMEOUT.unit)
}
environment {
// ENVs for check-compliance
GH_TOKEN = credentials('nordicbuilder-compliance-token') // This token is used to by check_compliance to comment on PRs and use checks
GH_USERNAME = "NordicBuilder"
COMPLIANCE_ARGS = "-r NordicPlayground/fw-nrfconnect-zephyr --exclude-module Kconfig"
LC_ALL = "C.UTF-8"
// ENVs for sanitycheck
ARCH = "-a arm"
SANITYCHECK_OPTIONS = "--inline-logs --enable-coverage --coverage-platform arm -N" // DEFAULT: --testcase-root tests
SANITYCHECK_RETRY_CMDS = '' // initialized so that it is shared to parrallel stages
}
stages {
stage('Load') { steps { script { CI_STATE = lib_State.load('ZEPHYR', CI_STATE) }}}
stage('Specification') { steps { script {
def TestStages = [:]
TestStages["compliance"] = {
node (CI_STATE.CFG.AGENT_LABELS) {
stage('Compliance Test'){
println "Using Node:$NODE_NAME"
docker.image("$CI_STATE.CFG.DOCKER_REG/$CI_STATE.CFG.IMAGE_TAG").inside {
dir('zephyr') {
checkout scm
CI_STATE.SELF.REPORT_SHA = lib_Main.checkoutRepo(
CI_STATE.SELF.GIT_URL, "ZEPHYR", CI_STATE.SELF, false)
lib_Status.set("PENDING", 'ZEPHYR', CI_STATE);
lib_West.AddManifestUpdate("ZEPHYR", 'zephyr',
CI_STATE.SELF.GIT_URL, CI_STATE.SELF.GIT_REF, CI_STATE)
}
lib_West.InitUpdate('zephyr')
lib_West.ApplyManifestUpdates(CI_STATE)
dir('zephyr') {
def BUILD_TYPE = lib_Main.getBuildType(CI_STATE.SELF)
if (BUILD_TYPE == "PR") {
if (CI_STATE.SELF.IS_MERGEUP) {
println 'This is a MERGE-UP PR. CI_STATE.SELF.IS_MERGEUP=' + CI_STATE.SELF.IS_MERGEUP
CI_STATE.SELF.MERGEUP_BASE = sh( script: "git log --oneline --grep='\\[nrf mergeup\\].*' -i -n 1 --pretty=format:'%h' | tr -d '\\n'" , returnStdout: true)
println "CI_STATE.SELF.MERGEUP_BASE = $CI_STATE.SELF.MERGEUP_BASE"
COMMIT_RANGE = "$CI_STATE.SELF.MERGEUP_BASE..$CI_STATE.SELF.REPORT_SHA"
} else {
COMMIT_RANGE = "$CI_STATE.SELF.MERGE_BASE..$CI_STATE.SELF.REPORT_SHA"
}
COMPLIANCE_ARGS = "$COMPLIANCE_ARGS -p $CHANGE_ID -S $CI_STATE.SELF.REPORT_SHA -g"
println "Building a PR [$CHANGE_ID]: $COMMIT_RANGE"
}
else if (BUILD_TYPE == "TAG") {
COMMIT_RANGE = "tags/${env.BRANCH_NAME}..tags/${env.BRANCH_NAME}"
println "Building a Tag: " + COMMIT_RANGE
}
// If not a PR, it's a non-PR-branch or master build. Compare against the origin.
else if (BUILD_TYPE == "BRANCH") {
COMMIT_RANGE = "origin/${env.BRANCH_NAME}..HEAD"
println "Building a Branch: " + COMMIT_RANGE
}
else {
assert condition : "Build fails because it is not a PR/Tag/Branch"
}
// Run the compliance check
try {
sh "(source ../zephyr/zephyr-env.sh && ../tools/ci-tools/scripts/check_compliance.py $COMPLIANCE_ARGS --commits $COMMIT_RANGE)"
}
finally {
junit 'compliance.xml'
archiveArtifacts artifacts: 'compliance.xml'
}
}
}
}
}
}
CI_STATE.SELF.IS_MERGEUP = false
if (CI_STATE.SELF.containsKey('CHANGE_TITLE')) {
if (((CI_STATE.SELF.CHANGE_TITLE.toLowerCase().contains('mergeup') ) || (CI_STATE.SELF.CHANGE_TITLE.toLowerCase().contains('upmerge') )) &&
((CI_STATE.SELF.CHANGE_BRANCH.toLowerCase().contains('mergeup') ) || (CI_STATE.SELF.CHANGE_BRANCH.toLowerCase().contains('upmerge') ))) {
CI_STATE.SELF.IS_MERGEUP = true
println 'This is a MERGE-UP PR. CI_STATE.SELF.IS_MERGEUP=' + CI_STATE.SELF.IS_MERGEUP
}
}
if (CI_STATE.SELF.CRON == 'COMMIT') {
println "Running Commit Tests"
} else if (CI_STATE.SELF.CRON == 'NIGHTLY') {
println "Running Nightly Tests"
} else if (CI_STATE.SELF.CRON == 'WEEKLY') {
println "Running Weekly Tests"
}
if (CI_STATE.SELF.RUN_TESTS) {
TestExecutionList['compliance'] = TestStages["compliance"]
}
if (CI_STATE.SELF.RUN_BUILD) {
def SUBSET_LIST = ['1/4', '2/4', '3/4', '4/4' ]
def COMPILER_LIST = ['gnuarmemb'] // 'zephyr',
def INPUT_MAP = [set : SUBSET_LIST, compiler : COMPILER_LIST ]
def OUTPUT_MAP = INPUT_MAP.values().combinations { args ->
[INPUT_MAP.keySet().toList(), args].transpose().collectEntries { [(it[0]): it[1]]}
}
SANITYCHECK_RETRY_CMDS_LIST = []
if (!CI_STATE.SELF.SANITYCHECK_RETRY_NUM) {
CI_STATE.SELF.SANITYCHECK_RETRY_NUM='7'
}
for (i=1; i <= CI_STATE.SELF.SANITYCHECK_RETRY_NUM.toInteger(); i++) {
SANITYCHECK_RETRY_CMDS_LIST.add("(sleep 30; ./scripts/sanitycheck $SANITYCHECK_OPTIONS --only-failed)")
}
SANITYCHECK_RETRY_CMDS = SANITYCHECK_RETRY_CMDS_LIST.join(' || \n')
def sanityCheckNRFStages = OUTPUT_MAP.collectEntries {
["SanityCheckNRF\n${it.compiler}\n${it.set}" : generateParallelStageNRF(it.set, it.compiler, JOB_NAME, CI_STATE)]
}
TestExecutionList = TestExecutionList.plus(sanityCheckNRFStages)
if (CI_STATE.SELF.RUN_BUILD_UPSTREAM) {
def sanityCheckALLStages = OUTPUT_MAP.collectEntries {
["SanityCheckALL\nzephyr\n${it.set}" : generateParallelStageALL(it.set, 'zephyr', JOB_NAME, CI_STATE)]
}
TestExecutionList = TestExecutionList.plus(sanityCheckALLStages)
}
}
println "TestExecutionList = $TestExecutionList"
}}}
stage('Execution') { steps { script {
parallel TestExecutionList
}}}
stage('Trigger Downstream Jobs') {
when { expression { CI_STATE.SELF.RUN_DOWNSTREAM } }
steps { script { lib_Stage.runDownstream(JOB_NAME, CI_STATE) } }
}
stage('Report') {
when { expression { CI_STATE.SELF.RUN_TESTS } }
steps { script {
println 'no report generation yet'
} }
}
}
post {
// This is the order that the methods are run. {always->success/abort/failure/unstable->cleanup}
always {
echo "always"
script { if ( !CI_STATE.SELF.RUN_BUILD && !CI_STATE.SELF.RUN_TESTS ) { currentBuild.result = "UNSTABLE"}}
}
success {
echo "success"
script { lib_Status.set("SUCCESS", 'ZEPHYR', CI_STATE) }
}
aborted {
echo "aborted"
script { lib_Status.set("ABORTED", 'ZEPHYR', CI_STATE) }
}
unstable {
echo "unstable"
script { lib_Status.set("FAILURE", 'ZEPHYR', CI_STATE) }
}
failure {
echo "failure"
script { lib_Status.set("FAILURE", 'ZEPHYR', CI_STATE) }
}
cleanup {
echo "cleanup"
cleanWs()
}
}
}
def generateParallelStageNRF(subset, compiler, JOB_NAME, CI_STATE) {
return {
node (CI_STATE.CFG.AGENT_LABELS) {
try {
stage('Sanity Check - Zephyr'){
println "Using Node:$NODE_NAME"
docker.image("$CI_STATE.CFG.DOCKER_REG/$CI_STATE.CFG.IMAGE_TAG").inside {
dir('zephyr') {
checkout scm
CI_STATE.SELF.REPORT_SHA = lib_Main.checkoutRepo(
CI_STATE.SELF.GIT_URL, "ZEPHYR", CI_STATE.SELF, false)
lib_West.AddManifestUpdate("ZEPHYR", 'zephyr',
CI_STATE.SELF.GIT_URL, CI_STATE.SELF.GIT_REF, CI_STATE)
}
lib_West.InitUpdate('zephyr')
lib_West.ApplyManifestUpdates(CI_STATE)
dir('zephyr') {
def PLATFORM_ARGS = lib_Main.getPlatformArgs(CI_STATE.SELF.PLATFORMS)
println "$compiler SANITY NRF PLATFORMS_ARGS = $PLATFORM_ARGS"
sh """
export ZEPHYR_TOOLCHAIN_VARIANT='$compiler' && \
source zephyr-env.sh && \
./scripts/sanitycheck $SANITYCHECK_OPTIONS $ARCH $PLATFORM_ARGS --subset $subset || $SANITYCHECK_RETRY_CMDS
"""
}
}
}
} finally {
cleanWs(); echo "Run: cleanWs()"
}
}
}
}
def generateParallelStageALL(subset, compiler, JOB_NAME, CI_STATE) {
return {
node (CI_STATE.CFG.AGENT_LABELS) {
try {
stage('Sanity Check - Zephyr'){
println "Using Node:$NODE_NAME"
docker.image("$CI_STATE.CFG.DOCKER_REG/$CI_STATE.CFG.IMAGE_TAG").inside {
dir('zephyr') {
checkout scm
CI_STATE.SELF.REPORT_SHA = lib_Main.checkoutRepo(
CI_STATE.SELF.GIT_URL, "ZEPHYR", CI_STATE.SELF, false)
lib_West.AddManifestUpdate("ZEPHYR", 'zephyr',
CI_STATE.SELF.GIT_URL, CI_STATE.SELF.GIT_REF, CI_STATE)
}
lib_West.InitUpdate('zephyr')
lib_West.ApplyManifestUpdates(CI_STATE)
dir('zephyr') {
sh """
export ZEPHYR_TOOLCHAIN_VARIANT='$compiler' && \
source zephyr-env.sh && \
./scripts/sanitycheck $SANITYCHECK_OPTIONS $ARCH --subset $subset || $SANITYCHECK_RETRY_CMDS
"""
}
}
}
} finally {
cleanWs(); echo "Ran: cleanWs()"
}
}
}
}
def generateComplianceStage(AGENT_LABELS, DOCKER_REG, IMAGE_TAG, JOB_NAME, CI_STATE) {
return {
node (AGENT_LABELS) {
try {
stage('Compliance Test'){
println "Using Node:$NODE_NAME"
docker.image("$DOCKER_REG/$IMAGE_TAG").inside {
dir('zephyr') {
checkout scm
CI_STATE.ZEPHYR.REPORT_SHA = lib_Main.checkoutRepo(
CI_STATE.ZEPHYR.GIT_URL, "ZEPHYR", CI_STATE.ZEPHYR, false)
lib_Status.set("PENDING", 'ZEPHYR', CI_STATE);
lib_West.AddManifestUpdate("ZEPHYR", 'zephyr',
CI_STATE.ZEPHYR.GIT_URL, CI_STATE.ZEPHYR.GIT_REF, CI_STATE)
}
lib_West.InitUpdate('zephyr')
lib_West.ApplyManifestUpdates(CI_STATE)
dir('zephyr') {
def BUILD_TYPE = lib_Main.getBuildType(CI_STATE.ZEPHYR)
if (BUILD_TYPE == "PR") {
if (CI_STATE.ZEPHYR.IS_MERGEUP) {
println 'This is a MERGE-UP PR. CI_STATE.ZEPHYR.IS_MERGEUP=' + CI_STATE.ZEPHYR.IS_MERGEUP
CI_STATE.ZEPHYR.MERGEUP_BASE = sh( script: "git log --oneline --grep='\\[nrf mergeup\\].*' -i -n 1 --pretty=format:'%h' | tr -d '\\n'" , returnStdout: true)
println "CI_STATE.ZEPHYR.MERGEUP_BASE = $CI_STATE.ZEPHYR.MERGEUP_BASE"
COMMIT_RANGE = "$CI_STATE.ZEPHYR.MERGEUP_BASE..$CI_STATE.ZEPHYR.REPORT_SHA"
} else {
COMMIT_RANGE = "$CI_STATE.ZEPHYR.MERGE_BASE..$CI_STATE.ZEPHYR.REPORT_SHA"
}
COMPLIANCE_ARGS = "$COMPLIANCE_ARGS -p $CHANGE_ID -S $CI_STATE.ZEPHYR.REPORT_SHA -g"
println "Building a PR [$CHANGE_ID]: $COMMIT_RANGE"
}
else if (BUILD_TYPE == "TAG") {
COMMIT_RANGE = "tags/${env.BRANCH_NAME}..tags/${env.BRANCH_NAME}"
println "Building a Tag: " + COMMIT_RANGE
}
// If not a PR, it's a non-PR-branch or master build. Compare against the origin.
else if (BUILD_TYPE == "BRANCH") {
COMMIT_RANGE = "origin/${env.BRANCH_NAME}..HEAD"
println "Building a Branch: " + COMMIT_RANGE
}
else {
assert condition : "Build fails because it is not a PR/Tag/Branch"
}
// Run the compliance check
try {
sh "source ../zephyr/zephyr-env.sh && \
pip install --user -r ../tools/ci-tools/requirements.txt && \
../tools/ci-tools/scripts/check_compliance.py $COMPLIANCE_ARGS --commits $COMMIT_RANGE"
}
finally {
junit 'compliance.xml'
archiveArtifacts artifacts: 'compliance.xml'
}
}
}
}
} finally {
cleanWs(); echo "Ran: cleanWs()"
}
}
}
}