forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
232 lines (203 loc) · 8.79 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
#!/usr/bin/env groovy
def boards = []
def examples = []
def tests = []
def driver_tests = []
def pkg_tests = []
def periph_tests = []
def other_tests = []
def unittests = []
/* stop running jobs */
abortPreviousBuilds()
stage('setup') {
node ('master') {
sh '(( "\${RIOT_MIRROR}" )) && git -C "\${RIOT_MIRROR_DIR}" fetch --all'
deleteDir()
fetchPR(env.CHANGE_ID, "--depth=1", "")
/* get all boards */
boards = sh(returnStdout: true,
script: 'find $(pwd)/boards/* -maxdepth 0 -type d \\! -name "*-common" -exec basename {} \\;'
).trim().split('\n')
/* get all examples */
examples = sh(returnStdout: true,
script: 'find examples/* -maxdepth 1 -name Makefile -print0 | xargs -0 -n1 dirname'
).trim().split('\n')
/* get all tests */
tests = sh(returnStdout: true,
script: 'find tests/* -maxdepth 1 -name Makefile -print0 | xargs -0 -n1 dirname'
).trim().split('\n')
/* split tests into smaller sets */
for (int i=0; i < tests.size(); i++) {
if (tests[i].startsWith("tests/driver_")) {
driver_tests << tests[i]
}
else if (tests[i].startsWith("tests/pkg_")) {
pkg_tests << tests[i]
}
else if (tests[i].startsWith("tests/periph_")) {
periph_tests << tests[i]
}
else if (tests[i].startsWith("tests/unittests")) {
unittests << tests[i]
}
else {
other_tests << tests[i]
}
}
deleteDir()
}
}
stage('static-tests') {
node('linux && boards') {
deleteDir()
fetchPR(env.CHANGE_ID, "", "master:master")
def ret = sh(returnStatus: true,
script: """#!/bin/bash +x
declare -i RESULT=0
./dist/tools/static-tests.sh >> success_static-tests.log 2>&1 || RESULT=1
if ((\$RESULT)); then
mv success_static-tests.log error_static-tests.log;
fi;
exit \$RESULT""")
if (ret) {
currentBuild.result = 'UNSTABLE'
}
step([$class: 'ArtifactArchiver', artifacts: "*_static-tests.log", fingerprint: true, allowEmptyArchive: true])
deleteDir()
}
}
stage("unittests") {
def builds = [:]
/* setup all concurrent builds */
def boardName = ""
for (int i=0; i < boards.size(); i++) {
boardName = boards[i]
builds['linux_unittests_' + boardName] = make_build("linux && boards && native", boardName, "linux_unittests", unittests)
}
/* distribute all builds to the slaves */
parallel (builds)
abortOnError("unittests failed")
}
stage("tests") {
def builds = [:]
/* setup all concurrent builds */
def boardName = ""
for (int i=0; i < boards.size(); i++) {
boardName = boards[i]
builds['linux_driver_tests_' + boardName] = make_build("linux && boards && native", boardName, "linux_driver_tests", driver_tests)
builds['linux_pkg_tests_' + boardName] = make_build("linux && boards && native", boardName, "linux_pkg_tests", pkg_tests)
builds['linux_periph_tests_' + boardName] = make_build("linux && boards && native", boardName, "linux_periph_tests", periph_tests)
builds['linux_other_tests_' + boardName] = make_build("linux && boards && native", boardName, "linux_other_tests", other_tests)
}
/* ignore macOS builds for now - macOS is currently broken for native
builds['macOS_driver_tests_native'] = make_build("macOS && native", "native", "macOS_driver_tests", driver_tests)
builds['macOS_pkg_tests_native'] = make_build("macOS && native", "native", "macOS_pkg_tests", pkg_tests)
builds['macOS_periph_tests_native'] = make_build("macOS && native", "native", "macOS_periph_tests", periph_tests)
builds['macOS_other_tests_native'] = make_build("macOS && native", "native", "macOS_other_tests", other_tests)
*/
/* ignore raspi builds for now - slows down the build (needs investigation)
builds['raspi_driver_tests_native'] = make_build("raspi && native", "native", "raspi_driver_tests", driver_tests)
builds['raspi_pkg_tests_native'] = make_build("raspi && native", "native", "raspi_pkg_tests", pkg_tests)
builds['raspi_periph_tests_native'] = make_build("raspi && native", "native", "raspi_periph_tests", periph_tests)
builds['raspi_other_tests_native'] = make_build("raspi && native", "native", "raspi_other_tests", other_tests)
*/
/* distribute all builds to the slaves */
parallel (builds)
abortOnError("tests failed")
}
stage("examples") {
def builds = [:]
/* setup all concurrent builds */
def boardName = ""
for (int i=0; i < boards.size(); i++) {
boardName = boards[i]
builds['linux_examples_' + boardName] = make_build("linux && boards && native", boardName, "linux_examples", examples)
}
/* ignore macOS builds for now - macOS is currently broken for native
builds['macOS_examples_native'] = make_build("macOS && native", "native", "macOS_examples", examples)
*/
/* ignore raspi builds for now - slows down the build (needs investigation)
builds['raspi_examples_native'] = make_build("raspi && native", "native", "raspi_examples", examples)
*/
/* distribute all builds to the slaves */
parallel (builds)
abortOnError("examples failed")
}
if (currentBuild.result == null) {
currentBuild.result = 'SUCCESS'
}
/* create a job */
def make_build(label, board, desc, arg)
{
return {
node(label) {
try {
deleteDir()
fetchPR(env.CHANGE_ID, "--depth=1", "")
def build_dir = pwd()
sh "./dist/tools/git/git-cache init"
timestamps {
def apps = arg.join(' ')
echo "building ${apps} for ${board} on nodes with ${label}"
withEnv([
"BOARD=${board}",
"CCACHE_BASEDIR=${build_dir}",
"RIOT_CI_BUILD=1"]) {
def ret = sh(returnStatus: true,
script: """#!/bin/bash +ex
declare -i RESULT=0
for app in ${apps}; do
if [[ \$(make -sC \$app info-boards-supported | tr ' ' '\n' | sed -n '/^${board}\$/p') ]]; then
echo \"\n\nBuilding \$app for ${board}\" >> success_${board}_${desc}.log
rm -rf jenkins_bin; mkdir jenkins_bin
CFLAGS_DBG=\"\" BINDIR=\$(pwd)/jenkins_bin make -j\${NPROC} -C \$app all >> success_${board}_${desc}.log 2>&1 || RESULT=1
fi;
done;
if ((\$RESULT)); then
mv success_${board}_${desc}.log error_${board}_${desc}.log
fi;
exit \$RESULT""")
if (ret) {
currentBuild.result = 'FAILURE'
}
step([$class: 'ArtifactArchiver', artifacts: "*_${board}_${desc}.log", fingerprint: true, allowEmptyArchive: true])
}
}
} catch(e) {
echo "${e.toString()}"
currentBuild.result = 'FAILURE'
} finally {
deleteDir()
}
}
}
}
/* abort previous, running builds */
def abortPreviousBuilds()
{
def buildnum = env.BUILD_NUMBER.toInteger()
def job = Jenkins.instance.getItemByFullName(env.JOB_NAME)
for (build in job.builds) {
if (!build.isBuilding() || (buildnum == build.getNumber().toInteger())) {
continue;
}
build.doStop();
}
}
def abortOnError(msg)
{
if ((currentBuild.result != null) && (currentBuild.result == 'FAILURE')) {
error msg
}
}
def fetchPR(prNum, fetchArgs, extraRefSpec)
{
sh """git init
if (( "\${RIOT_MIRROR}" )); then RIOT_URL="\${RIOT_MIRROR_URL}"; else RIOT_URL="https://github.com/RIOT-OS/RIOT"; fi
git remote add origin "\${RIOT_URL}"
for RETRIES in {1..3}; do
timeout 30 git fetch -u -n ${fetchArgs} origin ${extraRefSpec} pull/${prNum}/merge:pull_${prNum} && break
done
[[ "\$RETRIES" -eq 3 ]] && exit 1
git checkout pull_${prNum}"""
}