-
Notifications
You must be signed in to change notification settings - Fork 7
/
Jenkinsfile
305 lines (293 loc) · 11.5 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
@Library('[email protected]') _
def SW_NODE = "windows-slave"
def ECAT_NODE = "ecat-test"
def ECAT_NODE_LOCK = "test_execution_lock_ecat"
def CAN_NODE = "canopen-test"
def CAN_NODE_LOCK = "test_execution_lock_can"
def LIN_DOCKER_IMAGE = "ingeniacontainers.azurecr.io/docker-python:1.5"
def WIN_DOCKER_IMAGE = "ingeniacontainers.azurecr.io/win-python-builder:1.6"
def PUBLISHER_DOCKER_IMAGE = "ingeniacontainers.azurecr.io/publisher:1.8"
def DIST_FOE_APP_PATH = "ECAT-tools"
def LIB_FOE_APP_PATH = "ingenialink\\bin\\FOE"
def FOE_APP_NAME = "FoEUpdateFirmware.exe"
def FOE_APP_NAME_LINUX = "FoEUpdateFirmware"
def FOE_APP_VERSION = ""
DEFAULT_PYTHON_VERSION = "3.9"
ALL_PYTHON_VERSIONS = "py39,py310,py311,py312"
RUN_PYTHON_VERSIONS = ""
def PYTHON_VERSION_MIN = "py39"
def PYTHON_VERSION_MAX = "py312"
def BRANCH_NAME_MASTER = "master"
def DISTEXT_PROJECT_DIR = "doc/ingenialink-python"
coverage_stashes = []
def runTest(protocol, slave = 0) {
try {
bat "py -${DEFAULT_PYTHON_VERSION} -m tox -e ${RUN_PYTHON_VERSIONS} -- " +
"--protocol ${protocol} " +
"--slave ${slave} " +
"--cov=ingenialink " +
"--job_name=\"${env.JOB_NAME}-#${env.BUILD_NUMBER}-${protocol}-${slave}\""
} catch (err) {
unstable(message: "Tests failed")
} finally {
def coverage_stash = ".coverage_${protocol}_${slave}"
bat "move .coverage ${coverage_stash}"
junit "pytest_reports\\*.xml"
// Delete the junit after publishing it so it not re-published on the next stage
bat "del /S /Q pytest_reports\\*.xml"
stash includes: coverage_stash, name: coverage_stash
coverage_stashes.add(coverage_stash)
}
}
pipeline {
agent none
stages {
stage("Set run python versions") {
steps {
script {
if (env.BRANCH_NAME == 'master') {
RUN_PYTHON_VERSIONS = ALL_PYTHON_VERSIONS
} else if (env.BRANCH_NAME == 'develop') {
RUN_PYTHON_VERSIONS = ALL_PYTHON_VERSIONS
} else if (env.BRANCH_NAME.startsWith('release/')) {
RUN_PYTHON_VERSIONS = ALL_PYTHON_VERSIONS
} else {
RUN_PYTHON_VERSIONS = "${PYTHON_VERSION_MIN},${PYTHON_VERSION_MAX}"
}
}
}
}
stage('Get FoE application') {
agent {
docker {
label "worker"
image PUBLISHER_DOCKER_IMAGE
}
}
steps {
script {
FOE_APP_VERSION = sh(script: 'cd ingenialink/bin && python3.9 -c "import FoE; print(FoE.__version__)"', returnStdout: true).trim()
}
copyFromDist(".", "$DIST_FOE_APP_PATH/$FOE_APP_VERSION")
sh "mv FoEUpdateFirmwareLinux $FOE_APP_NAME_LINUX"
stash includes: "$FOE_APP_NAME,$FOE_APP_NAME_LINUX", name: 'foe_app'
}
}
stage('Build and Tests') {
parallel {
stage('Typing and formatting') {
agent {
docker {
label SW_NODE
image WIN_DOCKER_IMAGE
}
}
stages {
stage('Type checking') {
steps {
bat "py -${DEFAULT_PYTHON_VERSION} -m tox -e type"
}
}
stage('Format checking') {
steps {
bat "py -${DEFAULT_PYTHON_VERSION} -m tox -e format"
}
}
}
}
stage('Build wheels and documentation') {
agent {
docker {
label SW_NODE
image WIN_DOCKER_IMAGE
}
}
stages {
stage('Get FoE application') {
steps {
unstash 'foe_app'
bat """
XCOPY $FOE_APP_NAME $LIB_FOE_APP_PATH\\win_64x\\
XCOPY $FOE_APP_NAME_LINUX $LIB_FOE_APP_PATH\\linux\\
"""
}
}
stage('Build wheels') {
steps {
bat "py -${DEFAULT_PYTHON_VERSION} -m tox -e build"
}
}
stage('Generate documentation') {
steps {
bat "py -${DEFAULT_PYTHON_VERSION} -m tox -e docs"
}
}
stage('Archive') {
steps {
bat """
"C:\\Program Files\\7-Zip\\7z.exe" a -r docs.zip -w _docs -mem=AES256
"""
stash includes: 'dist\\*, docs.zip', name: 'publish_files'
archiveArtifacts artifacts: "dist\\*, docs.zip"
}
}
}
}
stage('Docker Windows - Tests') {
agent {
docker {
label SW_NODE
image WIN_DOCKER_IMAGE
}
}
stages {
stage('Run no-connection tests on docker') {
steps {
bat "py -${DEFAULT_PYTHON_VERSION} -m tox -e ${RUN_PYTHON_VERSIONS} -- " +
"-m docker " +
"--cov=ingenialink"
}
post {
always {
bat "move .coverage .coverage_docker"
junit "pytest_reports\\*.xml"
// Delete the junit after publishing it so it not re-published on the next stage
bat "del /S /Q pytest_reports\\*.xml"
stash includes: '.coverage_docker', name: '.coverage_docker'
script {
coverage_stashes.add(".coverage_docker")
}
}
}
}
}
}
stage('Docker Linux - Tests') {
agent {
docker {
label "worker"
image LIN_DOCKER_IMAGE
}
}
stages {
stage('Run no-connection tests on docker') {
steps {
sh """
python${DEFAULT_PYTHON_VERSION} -m tox -e ${RUN_PYTHON_VERSIONS}
"""
}
post {
always {
junit "pytest_reports\\*.xml"
}
}
}
}
}
stage('EtherCAT/No Connection - Tests') {
options {
lock(ECAT_NODE_LOCK)
}
agent {
label ECAT_NODE
}
stages {
stage('Get FoE application') {
steps {
unstash 'foe_app'
bat """
XCOPY $FOE_APP_NAME $LIB_FOE_APP_PATH\\win_64x\\
XCOPY $FOE_APP_NAME_LINUX $LIB_FOE_APP_PATH\\linux\\
"""
}
}
stage('EtherCAT Everest') {
steps {
runTest("ethercat", 0)
}
}
stage('EtherCAT Capitan') {
steps {
runTest("ethercat", 1)
}
}
stage('Run no-connection tests') {
steps {
runTest("no_connection")
}
}
}
}
stage('CANopen/Ethernet - Tests') {
options {
lock(CAN_NODE_LOCK)
}
agent {
label CAN_NODE
}
stages {
stage('CANopen Everest') {
steps {
runTest("canopen", 0)
}
}
stage('CANopen Capitan') {
steps {
runTest("canopen", 1)
}
}
stage('Ethernet Everest') {
steps {
runTest("ethernet", 0)
}
}
stage('Ethernet Capitan') {
steps {
runTest("ethernet", 1)
}
}
}
}
}
}
stage('Publish coverage') {
agent {
docker {
label SW_NODE
image WIN_DOCKER_IMAGE
}
}
steps {
script {
def coverage_files = ""
for (coverage_stash in coverage_stashes) {
unstash coverage_stash
coverage_files += " " + coverage_stash
}
bat "py -${DEFAULT_PYTHON_VERSION} -m tox -e coverage -- ${coverage_files}"
}
recordCoverage(tools: [[parser: 'COBERTURA', pattern: 'coverage.xml']])
archiveArtifacts artifacts: '*.xml'
}
}
stage('Publish wheels and documentation') {
agent {
docker {
label "worker"
image PUBLISHER_DOCKER_IMAGE
}
}
when {
beforeAgent true
branch BRANCH_NAME_MASTER
}
steps {
unstash 'publish_files'
unzip zipFile: 'docs.zip', dir: '.'
// Pending distext migration
// publishDistExt("_docs", DISTEXT_PROJECT_DIR, true)
publishPyPi("dist/*")
}
}
}
}