forked from ARMmbed/mbed-flasher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
270 lines (239 loc) · 7.12 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
echo "Start to build"
properties ([
buildDiscarder(
logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '',
daysToKeepStr: '30',
numToKeepStr: '100'
)
)
])
parallelSteps = [:]
parallelSteps['linux'] = streamStep('linux')
parallelSteps['windows'] = streamStep('windows')
def streamStep(nodeType) {
return {
node("mbed-flasher-${nodeType}") {
deleteDir()
try {
baseBuild()
} catch(err) {
throw err
} finally {
// clean up
step([$class: 'WsCleanup'])
}
}
}
}
def baseBuild() {
dir('mbed-flasher') {
// checkout scm
echo "checkout scm start"
def scmVars = checkout scm
env.GIT_COMMIT_HASH = scmVars.GIT_COMMIT
if (isUnix()) {
stage("linux py2") {
unittest("py2")
}
stage("linux py3") {
unittest("py3")
}
stage("pylint check") {
linux_pylint_check()
}
postBuild()
}
else {
stage("windows py2") {
winTest("py2")
}
stage("windows py3") {
winTest("py3")
}
}
}
}
def setBuildStatus(String state, String context, String message) {
step([
$class: "GitHubCommitStatusSetter",
reposSource: [
$class: "ManuallyEnteredRepositorySource",
url: "https://github.com/ARMmbed/mbed-flasher.git"
],
contextSource: [
$class: "ManuallyEnteredCommitContextSource",
context: context
],
errorHandlers: [[
$class: "ChangingBuildStatusErrorHandler",
result: "UNSTABLE"
]],
commitShaSource: [
$class: "ManuallyEnteredShaSource",
sha: env.GIT_COMMIT_HASH
],
statusResultSource: [
$class: 'ConditionalStatusResultSource',
results: [
[
$class: 'AnyBuildResult',
message: message,
state: state
]
]
]
])
}
def unittest(String pythonVersion) {
echo "set ${pythonVersion} github status"
String buildName = "linux ${pythonVersion} test"
setBuildStatus('PENDING', "${buildName}", 'test start')
try {
if (pythonVersion == "py3") {
// create python 3 venv
sh """
python3 -m venv .py3venv --without-pip
. .py3venv/bin/activate
curl https://bootstrap.pypa.io/get-pip.py | python
pip install coverage mock astroid==1.5.3 pylint==1.7.2
id
pip freeze
python setup.py install
coverage run -m unittest discover -s test -vvv
coverage html
coverage xml
deactivate
"""
} else {
// create python2 venv, do installation and run tests
sh """
virtualenv --python=../usr/bin/python .py2venv --no-site-packages
. .py2venv/bin/activate
id
pip install coverage mock astroid==1.5.3 pylint==1.7.2
pip freeze
python setup.py install
coverage run -m unittest discover -s test -vvv
coverage html --include='*mbed_flasher*' --directory=logs
coverage xml --include='*mbed_flasher*'
deactivate
"""
}
setBuildStatus('SUCCESS', "${buildName}", "test done")
} catch (err) {
echo "Caught exception: ${err}"
setBuildStatus('FAILURE', "${buildName}", "test failed")
currentBuild.result = 'FAILURE'
}
}
def linux_pylint_check() {
// execute pylint check shell (only linux)
echo "python 2 pylint check started"
sh """
. .py2venv/bin/activate
./run_pylint.sh | tee logs/pylint.log
deactivate
"""
echo "python3 pylint check started"
sh """
. .py3venv/bin/activate
./run_pylint.sh | tee logs/pylint3.log
deactivate
"""
// publish warnings
step([
$class: 'WarningsPublisher',
consoleParsers: [
[
parserName: 'GNU Make + GNU C Compiler (gcc)'
]
],
parserConfigurations: [
[
parserName: 'PyLint',
pattern: '**/pylint.log'
]
],
parserConfigurations: [
[
parserName: 'PyLint',
pattern: '**/pylint3.log'
]
],
unstableTotalAll: '0',
failedTotalAll: '0'
])
}
def winTest(String pythonVersion) {
echo "set ${pythonVersion} github status"
String buildName = "windows ${pythonVersion} test"
setBuildStatus('PENDING', "${buildName}", 'test start')
try {
if (pythonVersion == "py3") {
// create python 3 venv
echo 'hello windows py3 starts'
bat """
c:\\Python36\\python.exe -m venv py3venv
echo "Activating venv"
call py3venv\\Scripts\\activate.bat
pip install coverage mock
pip freeze
python setup.py install
coverage run -m unittest discover -s test -vvv
if %errorlevel% neq 0 exit /b %errorlevel%
coverage html & coverage xml
deactivate
"""
} else {
// create python2 venv, do installation and run tests
echo 'hello windows py2 starts'
bat """
virtualenv --python=c:\\Python27\\python.exe py2venv --no-site-packages
echo "Activating venv"
call py2venv\\Scripts\\activate.bat
pip install coverage mock
pip freeze
python setup.py install
coverage run -m unittest discover -s test -vvv
if %errorlevel% neq 0 exit /b %errorlevel%
coverage html & coverage xml
deactivate
"""
}
setBuildStatus('SUCCESS', "${buildName}", "test done")
} catch (err) {
echo "Caught exception: ${err}"
setBuildStatus('FAILURE', "${buildName}", "test failed")
currentBuild.result = 'FAILURE'
}
}
def postBuild() {
// Archive artifacts
catchError {
// nothing to archive
archiveArtifacts artifacts: "logs/*.*"
}
// Publish cobertura
catchError {
step([
$class: 'CoberturaPublisher',
coberturaReportFile: 'coverage.xml'
])
}
// Publish HTML reports
publishHTML(target: [
allowMissing: false,
alwayLinkToLastBuild: false,
keepAll: true,
reportDir: "logs",
reportFiles: "index.html",
reportName: "Build HTML Report"
])
}
timestamps {
timeout(time: 40, unit: "MINUTES") {
parallel parallelSteps
}
}