1- /*
2- # -----------------------------------------------------------------------------
3- # Author: MIRKO THULKE
4- # Copyright (c) 2025, MIRKO THULKE
5- # All rights reserved.
6- #
7- # Date: 2025, VERSAILLES, FRANCE
8- #
9- # MIT License
10- #
11- # Permission is hereby granted, free of charge, to any person obtaining a copy
12- # of this software and associated documentation files (the "Software"), to deal
13- # in the Software without restriction, including without limitation the rights
14- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15- # copies of the Software, and to permit persons to whom the Software is
16- # furnished to do so, subject to the following conditions:
17- #
18- # The above copyright notice and this permission notice shall be included in all
19- # copies or substantial portions of the Software.
20- #
21- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23- # FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
25- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING
26- # FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27- # IN THE SOFTWARE.
28- #
29- # -----------------------------------------------------------------------------
30- */
1+ // -----------------------------------------------------------------
2+ // Author: MIRKO THULKE
3+ // Copyright (c) 2025, MIRKO THULKE
4+ // All rights reserved.
5+ //
6+ // Date: 2025, VERSAILLES, FRANCE
7+ //
8+ // MIT License
9+ //
10+ // Permission is hereby granted, free of charge, to any person obtaining a copy
11+ // of this software and associated documentation files (the "Software"), to deal
12+ // in the Software without restriction, including without limitation the rights
13+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+ // copies of the Software, and to permit persons to whom the Software is
15+ // furnished to do so, subject to the following conditions:
16+ //
17+ // The above copyright notice and this permission notice shall be included in all
18+ // copies or substantial portions of the Software.
19+ //
20+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+ // FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
24+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING
25+ // FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26+ // IN THE SOFTWARE.
27+ //
28+ // -----------------------------------------------------------------------------
3129
32- /*
33- pytest options :
34- pytest --junitxml=report.xml : creates a report, which includes error messages
35- pytest--capture=tee-sys : also adds print statements to the report
36- pytest : by default the jenkins pipeline will stop and fail if test functions fail
37- pytest : currentBuild.result = 'UNSTABLE' -> this attribute allows , to let the build pass, but mark it as partly failed.
3830
39- #########################
40- # Pytest calls all functions starting with "test_" automatically
41- # hence, functions to be called by pytest MUST start with "test_"
4231
43- # Unit test howto :
44- # https://youtu.be/6tNS--WetLI?feature=shared
32+ // pytest options :
33+ // pytest --junitxml=report.xml : creates a report, which includes error messages
34+ // pytest--capture=tee-sys : also adds print statements to the report
35+ // pytest : by default the jenkins pipeline will stop and fail if test functions fail
36+ // pytest : currentBuild.result = 'UNSTABLE' -> this attribute allows , to let the build pass, but mark it as partly failed.
37+
38+ // #########################
39+ // Pytest calls all functions starting with "test_" automatically
40+ // hence, functions to be called by pytest MUST start with "test_"
41+
42+ // Unit test howto :
43+ // https://youtu.be/6tNS--WetLI?feature=shared
44+
4545
46- */
4746
4847
4948pipeline {
@@ -125,15 +124,16 @@ pipeline {
125124 echo " Running Python config integration test..."
126125
127126 script {
128- def error_flag
127+ def error_flag = 0
128+
129129 if (isUnix()) {
130130 error_flag = sh(
131- script : ' pytest --junitxml=report .xml --capture=tee-sys tests/integration_tests/test_pythonConfig.py' ,
131+ script : ' pytest --junitxml=report_integration_test_config .xml --capture=tee-sys tests/integration_tests/test_pythonConfig.py' ,
132132 returnStatus : true
133133 )
134134 } else {
135135 error_flag = bat(
136- script : ' pytest --junitxml=report .xml --capture=tee-sys tests/integration_tests/test_pythonConfig.py' ,
136+ script : ' pytest --junitxml=report_integration_test_config .xml --capture=tee-sys tests/integration_tests/test_pythonConfig.py' ,
137137 returnStatus : true
138138 )
139139 }
@@ -155,15 +155,16 @@ pipeline {
155155 echo " Running functional integration tests..."
156156
157157 script {
158- def error_flag
158+ def error_flag = 0
159+
159160 if (isUnix()) {
160161 error_flag = sh(
161- script : ' pytest --junitxml=report .xml --capture=tee-sys tests/integration_tests/test_integration_audioProcessing.py' ,
162+ script : ' pytest --junitxml=report_integration_test_functional .xml --capture=tee-sys tests/integration_tests/test_integration_audioProcessing.py' ,
162163 returnStatus : true
163164 )
164165 } else {
165166 error_flag = bat(
166- script : ' pytest --junitxml=report .xml --capture=tee-sys tests/integration_tests/test_integration_audioProcessing.py' ,
167+ script : ' pytest --junitxml=report_integration_test_functional .xml --capture=tee-sys tests/integration_tests/test_integration_audioProcessing.py' ,
167168 returnStatus : true
168169 )
169170 }
@@ -183,20 +184,40 @@ pipeline {
183184 echo " Running unit tests..."
184185
185186 script {
186- def error_flag_lowpass = bat(script : ' pytest --junitxml=report.xml --capture=tee-sys tests/unit_tests/test_unit_lowpass.py' , returnStatus : true )
187- def error_flag_aweighted = bat(script : ' pytest --junitxml=report.xml --capture=tee-sys tests/unit_tests/test_unit_aweighted.py' , returnStatus : true )
188- }
187+ def error_flag_lowpass = 0
188+ def error_flag_aweighted = 0
189+
190+ if (isUnix()) {
191+ error_flag_lowpass = sh(script : ' pytest --junitxml=report_lowpass.xml --capture=tee-sys tests/unit_tests/test_unit_lowpass.py' , returnStatus : true )
192+ error_flag_aweighted = sh(script : ' pytest --junitxml=report_aweighted.xml --capture=tee-sys tests/unit_tests/test_unit_aweighted.py' , returnStatus : true )
193+ } else {
194+ error_flag_lowpass = bat(script : ' pytest --junitxml=report_lowpass.xml --capture=tee-sys tests/unit_tests/test_unit_lowpass.py' , returnStatus : true )
195+ error_flag_aweighted = bat(script : ' pytest --junitxml=report_aweighted.xml --capture=tee-sys tests/unit_tests/test_unit_aweighted.py' , returnStatus : true )
196+ }
197+
198+ if (error_flag_lowpass != 0 || error_flag_aweighted != 0 ) {
199+ error " Unit tests failed!"
200+ }
201+
202+ }
189203 }
190204 }
191205
192206
193207 stage(' Smoke Test' ) {
194208 steps {
195209 echo " Running smoke tests..."
196-
210+
211+ def error_flag = 0
212+
197213 script {
198- def error_flag = bat(script : ' pytest --junitxml=report.xml --capture=tee-sys tests/smoke_tests/test_smoke_audioInput.py' , returnStatus : true )
199- }
214+
215+ if (isUnix()) {
216+ error_flag = sh(script : ' pytest --junitxml=report_smoke_test.xml --capture=tee-sys tests/smoke_tests/test_smoke_audioInput.py' , returnStatus : true )
217+ } else {
218+ error_flag = bat(script : ' pytest --junitxml=report_smoke_test.xml --capture=tee-sys tests/smoke_tests/test_smoke_audioInput.py' , returnStatus : true )
219+ }
220+ }
200221 }
201222 }
202223
@@ -215,55 +236,79 @@ pipeline {
215236 post {
216237
217238 always {
218- junit ' report.xml' // publish results
239+ junit ' report_integration_test_config.xml' // publish results
240+ junit ' report_integration_test_functional.xml' // publish results
241+ junit ' report_lowpass.xml' // publish results
242+ junit ' report_aweighted.xml' // publish results
243+ junit ' report_smoke_test.xml' // publish results
219244 echo " Pipeline finished."
220245 }
221246
222- success {
223- script
224- {
225-
226-
227- withCredentials([string(credentialsId : ' mirko-github-api-token' , variable : ' GITHUB_TOKEN' )]) {
228- bat """
229- curl -H "Authorization: token %GITHUB_TOKEN%" ^
230- -H "Accept: application/vnd.github.v3+json" ^
231- -X POST https://api.github.com/repos/${ env.REPO} /statuses/${ env.COMMIT_SHA} ^
232- -d "{\\ "state\\ ": \\ "pending\\ ", \\ "context\\ ": \\ "jenkins/build\\ ", \\ "description\\ ": \\ "Build started\\ "}"
233- """
234- }
235- }
236- }
237-
238- failure {
239- script {
240-
241-
242- withCredentials([string(credentialsId : ' mirko-github-api-token' , variable : ' GITHUB_TOKEN' )]) {
243- bat """
244- curl -H "Authorization: token %GITHUB_TOKEN%" ^
245- -H "Accept: application/vnd.github.v3+json" ^
246- -X POST https://api.github.com/repos/${ env.REPO} /statuses/${ env.COMMIT_SHA} ^
247- -d "{\\ "state\\ ": \\ "pending\\ ", \\ "context\\ ": \\ "jenkins/build\\ ", \\ "description\\ ": \\ "Build started\\ "}"
248- """
249- }
250- }
251- }
252-
253- unstable {
254- script {
255-
256-
257- withCredentials([string(credentialsId : ' mirko-github-api-token' , variable : ' GITHUB_TOKEN' )]) {
258- bat """
259- curl -H "Authorization: token %GITHUB_TOKEN%" ^
260- -H "Accept: application/vnd.github.v3+json" ^
261- -X POST https://api.github.com/repos/${ env.REPO} /statuses/${ env.COMMIT_SHA} ^
262- -d "{\\ "state\\ ": \\ "pending\\ ", \\ "context\\ ": \\ "jenkins/build\\ ", \\ "description\\ ": \\ "Build started\\ "}"
263- """
264- }
265- }
266- }
267- }
247+
248+ success {
249+ script {
250+ withCredentials([string(credentialsId : ' mirko-github-api-token' , variable : ' GITHUB_TOKEN' )]) {
251+ if (isUnix()) {
252+ sh """
253+ curl -H "Authorization: token \$ GITHUB_TOKEN" \\
254+ -H "Accept: application/vnd.github.v3+json" \\
255+ -X POST https://api.github.com/repos/${ env.REPO} /statuses/${ env.COMMIT_SHA} \\
256+ -d '{\\ "state\\ ": \\ "success\\ ", \\ "context\\ ": \\ "jenkins/build\\ ", \\ "description\\ ": \\ "Build succeeded\\ "}'
257+ """
258+ } else {
259+ bat """
260+ curl -H "Authorization: token %GITHUB_TOKEN%" ^
261+ -H "Accept: application/vnd.github.v3+json" ^
262+ -X POST https://api.github.com/repos/${ env.REPO} /statuses/${ env.COMMIT_SHA} ^
263+ -d "{\\ "state\\ ": \\ "success\\ ", \\ "context\\ ": \\ "jenkins/build\\ ", \\ "description\\ ": \\ "Build succeeded\\ "}"
264+ """
265+ }
266+ }
267+ }
268+ }
269+
270+ failure {
271+ script {
272+ withCredentials([string(credentialsId : ' mirko-github-api-token' , variable : ' GITHUB_TOKEN' )]) {
273+ if (isUnix()) {
274+ sh """
275+ curl -H "Authorization: token \$ GITHUB_TOKEN" \\
276+ -H "Accept: application/vnd.github.v3+json" \\
277+ -X POST https://api.github.com/repos/${ env.REPO} /statuses/${ env.COMMIT_SHA} \\
278+ -d '{\\ "state\\ ": \\ "failure\\ ", \\ "context\\ ": \\ "jenkins/build\\ ", \\ "description\\ ": \\ "Build failed\\ "}'
279+ """
280+ } else {
281+ bat """
282+ curl -H "Authorization: token %GITHUB_TOKEN%" ^
283+ -H "Accept: application/vnd.github.v3+json" ^
284+ -X POST https://api.github.com/repos/${ env.REPO} /statuses/${ env.COMMIT_SHA} ^
285+ -d "{\\ "state\\ ": \\ "failure\\ ", \\ "context\\ ": \\ "jenkins/build\\ ", \\ "description\\ ": \\ "Build failed\\ "}"
286+ """
287+ }
288+ }
289+ }
290+ }
268291
292+ unstable {
293+ script {
294+ withCredentials([string(credentialsId : ' mirko-github-api-token' , variable : ' GITHUB_TOKEN' )]) {
295+ if (isUnix()) {
296+ sh """
297+ curl -H "Authorization: token \$ GITHUB_TOKEN" \\
298+ -H "Accept: application/vnd.github.v3+json" \\
299+ -X POST https://api.github.com/repos/${ env.REPO} /statuses/${ env.COMMIT_SHA} \\
300+ -d '{\\ "state\\ ": \\ "pending\\ ", \\ "context\\ ": \\ "jenkins/build\\ ", \\ "description\\ ": \\ "Build unstable\\ "}'
301+ """
302+ } else {
303+ bat """
304+ curl -H "Authorization: token %GITHUB_TOKEN%" ^
305+ -H "Accept: application/vnd.github.v3+json" ^
306+ -X POST https://api.github.com/repos/${ env.REPO} /statuses/${ env.COMMIT_SHA} ^
307+ -d "{\\ "state\\ ": \\ "pending\\ ", \\ "context\\ ": \\ "jenkins/build\\ ", \\ "description\\ ": \\ "Build unstable\\ "}"
308+ """
309+ }
310+ }
311+ }
312+ }
313+
269314}
0 commit comments