-
Notifications
You must be signed in to change notification settings - Fork 93
/
Jenkinsfile
158 lines (137 loc) · 5.01 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
properties ([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
[$class: 'StringParameterDefinition', name: 'mbed_os_revision', defaultValue: '', description: 'Revision of mbed-os to build. To access mbed-os PR use format "pull/PR number/head"'],
[$class: 'BooleanParameterDefinition', name: 'regions_build_test', defaultValue: true, description: 'Test build all available regions']
]]])
library 'mbed-lib'
if (env.MBED_OS_REVISION == null) {
echo 'First run in this branch, using default parameter values'
env.MBED_OS_REVISION = ''
}
if (env.MBED_OS_REVISION == '') {
echo 'Using mbed OS revision from mbed-os.lib'
} else {
echo "Using given mbed OS revision: ${env.MBED_OS_REVISION}"
if (env.MBED_OS_REVISION.matches('pull/\\d+/head')) {
echo "Revision is a Pull Request"
}
}
// All available regions
def regions = [
"\"0\"", "\"1\"", "\"2\"", "\"3\"", "\"4\"", "\"5\"", "\"6\"", "\"7\"", "\"8\"",
"\"EU868\"", "\"AS923\"", "\"AU915\"", "\"CN470\"", "\"CN779\"", "\"EU433\"",
"\"IN865\"", "\"KR920\"", "\"US915\""
]
// Supported targets
def targets = [
"K64F",
"MTS_MDOT_F411RE",
"DISCO_L072CZ_LRWAN1"
]
// Supported toolchains
def toolchains = [
"ARM",
"GCC_ARM"
]
def stepsForParallel = [:]
// Jenkins pipeline does not support map.each, we need to use oldschool for loop
for (int i = 0; i < targets.size(); i++) {
for(int j = 0; j < toolchains.size(); j++) {
def target = targets.get(i)
def toolchain = toolchains.get(j)
// Skip unwanted combination
if (target == "DISCO_L072CZ_LRWAN1" && toolchain == "GCC_ARM") {
continue
}
def stepName = "${target} ${toolchain}"
stepsForParallel[stepName] = buildStep(target, toolchain)
}
}
def stepsForRegional = [:]
if (params.regions_build_test == true) {
stepsForRegional["REGION BUILDER"] = build_regions(regions)
}
timestamps {
parallel stepsForParallel
parallel stepsForRegional
}
def buildStep(target, toolchain) {
return {
stage ("${target}_${toolchain}") {
node ("all-in-one-build-slave") {
deleteDir()
dir("mbed-os-example-lorawan") {
checkout scm
// A workaround for mbed-cli caching issues
try {
execute("mbed deploy --protocol ssh")
} catch (err) {
echo "mbed deploy failed - retrying after 10s"
sleep(10)
execute("mbed deploy --protocol ssh")
}
// Set mbed-os to revision received as parameter
if (env.MBED_OS_REVISION != '') {
dir("mbed-os") {
if (env.MBED_OS_REVISION.matches('pull/\\d+/head')) {
// Use mbed-os PR and switch to branch created
execute("git fetch origin ${env.MBED_OS_REVISION}:_PR_")
execute("git checkout _PR_")
} else {
execute("git checkout ${env.MBED_OS_REVISION}")
}
}
}
// Adjust stack size and crystal values
if ("${target}" == "DISCO_L072CZ_LRWAN1") {
execute("sed -i 's/#define RCC_HSICALIBRATION_DEFAULT ((uint32_t)0x10)/#define RCC_HSICALIBRATION_DEFAULT ((uint32_t)0x13)/' \
mbed-os/targets/TARGET_STM/TARGET_STM32L0/device/stm32l0xx_hal_rcc.h")
}
execute("mbed compile --build out/${target}_${toolchain}/ -m ${target} -t ${toolchain} -c")
}
stash name: "${target}_${toolchain}", includes: '**/mbed-os-example-lorawan.bin'
archive '**/mbed-os-example-lorawan.bin'
step([$class: 'WsCleanup'])
}
}
}
}
def build_regions(regions) {
return {
stage ("region_builder_K64F_GCC_ARM") {
node ("all-in-one-build-slave") {
deleteDir()
dir("mbed-os-example-lorawan") {
checkout scm
// A workaround for mbed-cli caching issues
try {
execute("mbed deploy --protocol ssh")
} catch (err) {
echo "mbed deploy failed - retrying after 10s"
sleep(10)
execute("mbed deploy --protocol ssh")
}
if (env.MBED_OS_REVISION != '') {
dir("mbed-os") {
if (env.MBED_OS_REVISION.matches('pull/\\d+/head')) {
execute("git fetch origin ${env.MBED_OS_REVISION}:_PR_")
execute("git checkout _PR_")
} else {
execute("git checkout ${env.MBED_OS_REVISION}")
}
}
}
//Initial sed to string format for find & replacing
execute("sed -i 's/\"lora.phy\": 0,/\"lora.phy\": \"0\",/' mbed_app.json")
//lora.phy 0 build tested above already
for (int i = 1; i < regions.size(); i++) {
def curr_region = regions.get(i)
def prev_region = regions.get(i-1)
execute("sed -i 's/\"lora.phy\": ${prev_region},/\"lora.phy\": ${curr_region},/' mbed_app.json")
echo "Building region: ${curr_region}"
execute("mbed compile -t GCC_ARM -m K64F")
}
}
}
}
}
}