forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
219 lines (193 loc) · 8.57 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
#!/usr/bin/env groovy
def boards = []
def examples = []
def tests = []
def driver_tests = []
def pkg_tests = []
def periph_tests = []
def other_tests = []
def unittests = []
githubNotify context: 'Jenkins', description: 'Build started', status: 'PENDING', targetUrl: "${env.BUILD_URL}artifact"
/* stop running jobs */
abortPreviousBuilds()
node ('master') {
stage('setup') {
deleteDir()
checkout scm
/* also fetch master branch - necessary for static tests */
sh "git fetch origin master:master"
/* stash workspace for slaves */
stash 'sources'
/* 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]
}
}
}
stage('static-tests') {
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])
}
}
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")
}
def buildState = 'SUCCESS'
if (currentBuild.result == null) {
currentBuild.result = 'SUCCESS'
}
else if (currentBuild.result != 'SUCCESS') {
buildState = 'FAILURE'
}
/* set commit status in GitHub with url pointing to logs manually (necessary workaround for now) */
githubNotify context: 'Jenkins', description: "${currentBuild.result}", status: buildState, targetUrl: "${env.BUILD_URL}artifact"
/* create a job */
def make_build(label, board, desc, arg)
{
return {
node(label) {
try {
deleteDir()
unstash 'sources'
def build_dir = pwd()
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
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'
}
}
}
}
/* 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')) {
githubNotify context: 'Jenkins', description: msg, status: 'FAILURE', targetUrl: "${env.BUILD_URL}artifact"
error msg
}
}