blob: 2a4d751dfbcd831c72f14a3d0d4e5795eadb99aa [file] [log] [blame]
Dean Birch62c4f082020-01-17 16:13:26 +00001#!/usr/bin/env groovy
2//-------------------------------------------------------------------------------
Xinyu Zhang29a57cc2023-02-03 10:08:48 +08003// Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.
Dean Birch62c4f082020-01-17 16:13:26 +00004//
5// SPDX-License-Identifier: BSD-3-Clause
6//
7//-------------------------------------------------------------------------------
8
Dean Birchd0f9f8c2020-03-26 11:10:33 +00009@Library('trustedfirmware') _
10import org.trustedfirmware.Gerrit
Dean Bircha6ede7e2020-03-13 14:00:33 +000011
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080012failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
13
Xinyu Zhang29a57cc2023-02-03 10:08:48 +080014@NonCPS
15def isPerPatchJob() {
16 def upstream_jobs = manager.build.getAction(hudson.model.CauseAction.class).getCauses()
17 if (upstream_jobs.size() > 0 && upstream_jobs[0] instanceof hudson.model.Cause.UpstreamCause) {
18 print("Parent project cause: ")
19 println(upstream_jobs[0].upstreamProject)
20 if (upstream_jobs[0].upstreamProject.endsWith("tf-m-static")) {
21 return true
22 }
23 }
24 return false
25}
26
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080027def submit_lava_tests(config, results, build_res, params, params_collection) {
28 print("Doing LAVA stuff for ${build_res.getAbsoluteUrl()}")
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080029 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
30 params += string(name: 'BUILD_URL', value: build_res.getAbsoluteUrl())
31 params += string(name: 'LAVA_URL', value: env.LAVA_URL)
Paul Sokolovskydaa430a2022-01-06 09:59:16 +030032 params += string(name: 'CI_SCRIPTS_REPO', value: env.CI_SCRIPTS_REPO)
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080033 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
34 params += string(name: 'LAVA_CREDENTIALS', value: env.LAVA_CREDENTIALS)
35 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Xinyu Zhang0c8d3202022-10-19 14:42:47 +080036 params += string(name: 'DEVICE_FILTER', value: env.DEVICE_FILTER)
Xinyu Zhang0aced4c2021-09-03 17:06:21 +080037 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
38 def lava_resubmitted = false
39 if (lava_res.result in failure_states) {
40 error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}")
41 } else {
42 lava_des = lava_res.getDescription()
43 if (lava_des.contains(" Submitted twice!")) {
44 lava_resubmitted = true
45 lava_des = lava_des - " Submitted twice!"
46 }
47 results['lava_jobs'] += lava_des
48 }
49 links = "Build Config: ${config}\n"
50 links += "Build URL: ${build_res.getAbsoluteUrl()}\n"
51 links += "LAVA Submit: ${lava_res.getAbsoluteUrl()}"
52 if (lava_resubmitted) {
53 links += "\nLAVA Job Re-Submitted!"
54 }
55 print(links)
56}
57
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +080058def listConfigs(config_list, filter_group) {
Xinyu Zhang4b109802022-10-18 17:22:07 +080059 def build_config_list_raw = sh(script:
60 """
Xinyu Zhang4b109802022-10-18 17:22:07 +080061 python3 ./tf-m-ci-scripts/configs.py -g ${filter_group.replace(" ", " -g ")}\n
Xinyu Zhang4b109802022-10-18 17:22:07 +080062 """, returnStdout: true).trim()
63 def build_config_list = build_config_list_raw.tokenize('\n')
64 config_list.addAll(build_config_list)
Dean Birch62c4f082020-01-17 16:13:26 +000065}
66
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +080067def obtainBuildParams(config) {
68 def build_params = [:]
Xinyu Zhang4b109802022-10-18 17:22:07 +080069 build_config_params = sh(script:
70 """
Xinyu Zhang46b37182023-06-30 15:36:44 +080071 python3 ./tf-m-ci-scripts/configs.py --config_params ${config}\n
Xinyu Zhang4b109802022-10-18 17:22:07 +080072 """, returnStdout: true).trim()
Dean Birch62c4f082020-01-17 16:13:26 +000073 def lines = build_config_params.tokenize('\n')
74 for (String line : lines) {
75 def key, value
76 (key, value) = line.tokenize('=')
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +080077 build_params[key] = value
78 }
79 return build_params
80}
81
82def buildConfig(config, results) {
83 def params = []
84 params_collection = obtainBuildParams(config)
85 params_collection.each { param ->
86 params += string(name: param.key, value:param.value)
Dean Birch62c4f082020-01-17 16:13:26 +000087 }
88 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +000089 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
90 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
91 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +000092 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Karl Zhang02d30352020-08-20 13:48:52 +080093 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Dean Birch62c4f082020-01-17 16:13:26 +000094 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Karl Zhangf6f467e2020-07-10 16:24:45 +080095 params += string(name: 'CODE_COVERAGE_EN', value: env.CODE_COVERAGE_EN)
Paul Sokolovskydaa430a2022-01-06 09:59:16 +030096 params += string(name: 'CI_SCRIPTS_REPO', value: env.CI_SCRIPTS_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +000097 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -050098 params += string(name: 'MCUBOOT_REFSPEC', value: env.MCUBOOT_REFSPEC)
99 params += string(name: 'MCUBOOT_URL', value: env.MCUBOOT_URL)
100 params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
Paul Sokolovsky8d288712022-01-13 00:53:03 +0300101 params += string(name: 'MBEDTLS_URL', value: env.MBEDTLS_URL)
Bence Balogh79fda442022-10-14 18:01:37 +0200102 params += string(name: 'TFM_EXTRAS_REFSPEC', value: env.TFM_EXTRAS_REFSPEC)
103 params += string(name: 'TFM_EXTRAS_URL', value: env.TFM_EXTRAS_URL)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500104 params += string(name: 'TFM_TESTS_REFSPEC', value: env.TFM_TESTS_REFSPEC)
105 params += string(name: 'TFM_TESTS_URL', value: env.TFM_TESTS_URL)
106 params += string(name: 'PSA_ARCH_TESTS_VERSION', value: env.PSA_ARCH_TESTS_VERSION)
107 params += string(name: 'PSA_ARCH_TESTS_URL', value: env.PSA_ARCH_TESTS_URL)
Xinyu Zhangc7ad0822022-11-23 17:54:26 +0800108 params += string(name: 'QCBOR_VERSION', value: env.QCBOR_VERSION)
109 params += string(name: 'QCBOR_URL', value: env.QCBOR_URL)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500110 params += string(name: 'SHARE_FOLDER', value: env.SHARE_FOLDER)
Xinyu Zhang470b3c42022-09-19 14:41:45 +0800111 params += string(name: 'SQUAD_CONFIGURATIONS', value: env.SQUAD_CONFIGURATIONS)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000112 return { -> results
113 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000114 def build_url = build_res.getAbsoluteUrl()
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800115 results['builds'][config] = build_res
Xinyu Zhang0aced4c2021-09-03 17:06:21 +0800116
Dean Bircha6ede7e2020-03-13 14:00:33 +0000117 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
Xinyu Zhangf2ba9112021-09-02 13:31:16 +0800118
119 // Filter out configs do not need LAVA tests
120
121 // Configs with build failure do not need LAVA tests
Xinyu Zhang6aa579a2022-04-20 11:36:27 +0800122 if (build_res.result in failure_states) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000123 error("Build failed at ${build_url}")
Arthur She3c0dadd2021-11-18 21:17:48 -0800124 } else {
125 // Build successful
Xinyu Zhang6aa579a2022-04-20 11:36:27 +0800126 // Job tf-m-extra-build does not need LAVA tests
127 if (env.JOB_NAME.equals("tf-m-extra-build")) {
128 print("LAVA is not needed in tf-m-extra-build job.")
129 }
Xinyu Zhang22a12752022-10-10 17:21:21 +0800130 // Submit LAVA tests
131 else {
Arthur She3c0dadd2021-11-18 21:17:48 -0800132 submit_lava_tests(config, results, build_res, params, params_collection)
Arthur She3c0dadd2021-11-18 21:17:48 -0800133 }
Dean Birch62c4f082020-01-17 16:13:26 +0000134 }
135 }
136}
137
Matthew Hart06340d72020-06-15 16:08:20 +0100138def buildDocs(results) {
Dean Birch62c4f082020-01-17 16:13:26 +0000139 def params = []
140 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000141 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
142 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
143 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +0000144 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
Dean Birch62c4f082020-01-17 16:13:26 +0000145 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Paul Sokolovskydaa430a2022-01-06 09:59:16 +0300146 params += string(name: 'CI_SCRIPTS_REPO', value: env.CI_SCRIPTS_REPO)
Colin Thorbinson58703db2020-11-24 12:02:19 +0000147 params += string(name: 'CI_SCRIPTS_BRANCH', value: env.CI_SCRIPTS_BRANCH)
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500148 params += string(name: 'SHARE_FOLDER', value: env.SHARE_FOLDER)
Matthew Hart06340d72020-06-15 16:08:20 +0100149 return { -> results
Dean Birch62c4f082020-01-17 16:13:26 +0000150 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
151 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Matthew Hart06340d72020-06-15 16:08:20 +0100152 results['docs'] = [res.number, res.result, params]
Dean Bircha6ede7e2020-03-13 14:00:33 +0000153 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +0000154 error("Build failed at ${res.getAbsoluteUrl()}")
155 }
156 }
157}
158
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800159def generateEmailBody(stage, results) {
160 // Results format: [CONFIG_NAME: [URL: "", RESULT: "", ...]]
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800161 failed_jobs = ""
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800162 results.each { job ->
163 if (job.value['RESULT'] == 'FAILURE') {
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800164 failed_jobs += "${job.key} ${job.value['URL']}\n"
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800165 }
Xinyu Zhang38a18872020-11-23 16:45:28 +0800166 }
167
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800168 if (failed_jobs == "") {
169 return ""
170 }
171
172 body = "Check console output at ${env.BUILD_URL} \n\n"
173 body += "Failed Jobs:\n${failed_jobs}"
Xinyu Zhang38a18872020-11-23 16:45:28 +0800174 body += "\nFor detailed ${stage} results please refer to \
175 ${env.BUILD_URL}artifact/${stage}_results.csv \n"
176 return body
177}
178
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800179def emailNotification(stage, results) {
Karl Zhang0413e972020-09-18 17:59:26 +0800180 script {
Xinyu Zhang953dc232022-09-07 18:27:35 +0800181 if (env.EMAIL_NOTIFICATION) {
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800182 email_body = generateEmailBody(stage, results)
183 if (email_body == "") {
184 print("Skip sending email notification as no failed jobs for ${stage}")
Karl Zhang182ecdf2020-10-10 09:52:12 +0800185 }
186 else {
187 emailext (
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800188 subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} fail"),
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800189 body: email_body,
Karl Zhang182ecdf2020-10-10 09:52:12 +0800190 to: "${EMAIL_NOTIFICATION}"
191 )
192 }
Karl Zhang0413e972020-09-18 17:59:26 +0800193 }
194 } /* script */
195}
196
Xinyu Zhang82dab282022-10-09 16:33:19 +0800197def parseTestResults(output) {
Xinyu Zhang82dab282022-10-09 16:33:19 +0800198 def test_results = [:]
199 records = output.split('\nLAVA Test Config:\n')
200 if (records.size() < 2) {
201 return test_results
202 }
203 records[1..-1].each { record ->
204 config_name = ""
205 metadata = [:]
206 record.split('\n').each { line ->
207 record_metadata = line.split(': ')
Paul Sokolovsky412d62a2022-12-02 21:35:22 +0300208 // Skip lines which are not "metadata"
209 if (record_metadata.size() < 2) {
210 return
211 }
Xinyu Zhang82dab282022-10-09 16:33:19 +0800212 if (record_metadata[0] == 'Config Name') {
213 config_name = record_metadata[1]
214 } else {
215 metadata[record_metadata[0]] = record_metadata[1]
216 }
217 }
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800218 test_results[config_name] = ['URL': metadata['LAVA link'],
219 'RESULT': metadata['Test Result']]
Xinyu Zhang82dab282022-10-09 16:33:19 +0800220 }
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800221
222 writeCsv(test_results, "test_results.csv")
223
Xinyu Zhang82dab282022-10-09 16:33:19 +0800224 return test_results
225}
226
Xinyu Zhang57d2d8c2022-10-24 14:27:30 +0800227def verifyTestStatus(output) {
228 g = new Gerrit()
229 if (output.contains('FAILURE')) {
230 score = -1
231 } else {
232 score = 1
233 }
234 g.verifyStatus(score, "lava_test", "test")
235 if (score < 0) {
236 error("Marking job as failed due to failed tests.")
237 }
238}
239
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800240def generateCsvContent(results) {
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800241 // Results format: [CONFIG_NAME: [URL: "", RESULT: "", ...]]
242 // CSV format: CONFIG_NAME, RESULT
243 csv_header = obtainBuildParams(results.keySet()[0]).keySet().toList()
244 csv_header.add('RESULT')
245 csv_content = [csv_header]
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800246 results.each { result ->
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800247 build_params = []
248 obtainBuildParams(result.key).each { config ->
249 build_params.add(config.value)
Xinyu Zhang4f2ef5a2020-11-09 18:11:43 +0800250 }
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800251 build_params.add(result.value['RESULT'])
252 csv_content.add(build_params)
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800253 }
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800254 return csv_content
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800255}
256
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800257def generateHtmlContent(results) {
258 // Results format: [CONFIG_NAME: [URL: "", RESULT: "", ...]]
259 // HTML format: CONFIG_NAME: Job/Logs/Artifacts RESULT
260 htmlContent = []
261 results.each { result ->
262 htmlContent.add("${result.key}: <a href=\"${result.value['URL']}\">Job</a>/<a href=\"${result.value['URL']}/consoleText\">Logs</a>/<a href=\"${result.value['URL']}/artifact/\">Artifacts</a> ${result.value['RESULT']}<br/>")
263 }
264 htmlContent.sort()
265 return htmlContent.join("\n")
266}
267
268def writeCsv(results, file_name) {
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800269 def csvContent = generateCsvContent(results)
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800270 writeCSV file: file_name, records: csvContent, format: CSVFormat.EXCEL
271 sh(script: """./tf-m-ci-scripts/report_parser/report_csv_helper.py \
272 --input-file ${file_name} --output-file ${file_name} \
273 """, returnStdout: true)
274 archiveArtifacts file_name
xinyu-tfmb4fc0412020-08-19 10:49:51 +0800275}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000276
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800277def writeHTML(results, file_name) {
278def buildLinks = generateHtmlContent(results)
279 writeFile file: file_name, text: buildLinks
280 archiveArtifacts file_name
Dean Bircha6ede7e2020-03-13 14:00:33 +0000281}
282
Matthew Hartfb6fd362020-03-04 21:03:59 +0000283def lineInString(string, match) {
284 def lines = string.split("\n")
285 def result = lines.findAll { it.contains(match) }
286 return result[0]
287}
288
289def getResult(string, match) {
290 line = lineInString(string, match)
Dean Birch1d545c02020-05-29 14:09:21 +0100291 a = line.split(match)[1].split(' ')
292 score = a[0]
293 if (a.size() > 1)
294 {
295 fail_text = a[1..-1].join(" ")
296 return [score, fail_text]
297 }
298 return [score, ""]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000299}
300
301def submitJobsToList(results) {
302 def all_jobs = []
303 for (String result : results){
304 jobs_s = result.split('JOBS: ')
305 if (jobs_s.size() > 1) {
306 all_jobs += jobs_s[1]
307 }
308 }
309 return(all_jobs)
310}
311
Dean Birch62c4f082020-01-17 16:13:26 +0000312def configs = []
313def builds = [:]
Matthew Hartfb6fd362020-03-04 21:03:59 +0000314def results = [:]
Dean Birch62c4f082020-01-17 16:13:26 +0000315
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800316timestamps {
317 node("docker-amd64-tf-m-bionic") {
318 stage("Init") {
319 cleanWs()
320 dir("tf-m-ci-scripts") {
321 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
Xinyu Zhang8472b852021-09-04 00:13:34 +0800322 sh "git rev-parse --short HEAD"
Leonardo Sandoval7090b2c2021-09-17 13:20:44 -0500323 // Clone TF-M repositories so share folder can be reused by downstream jobs
324 sh "./clone.sh"
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800325 }
326 }
Xinyu Zhang6b456c22022-10-13 15:48:58 +0800327
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800328 stage("Configs") {
Xinyu Zhang4b109802022-10-18 17:22:07 +0800329 dir(".") {
330 // Populate configs
331 listConfigs(configs, env.FILTER_GROUP)
332 results['builds'] = [:]
333 results['lava_jobs'] = []
334 for (config in configs) {
335 builds[config] = buildConfig(config, results)
336 }
337 if (!env.JOB_NAME.equals("tf-m-extra-build")) {
338 builds["docs"] = buildDocs(results)
339 }
Xinyu Zhang351f14c2021-11-15 14:30:09 +0800340 }
Dean Birch62c4f082020-01-17 16:13:26 +0000341 }
Karl Zhangfec84102020-06-24 09:56:36 +0800342
Xinyu Zhang6b456c22022-10-13 15:48:58 +0800343 stage("Builds") {
344 def verify = 1
345 def success = true
Xinyu Zhang4b109802022-10-18 17:22:07 +0800346 dir(".") {
347 try {
348 parallel(builds)
349 } catch (Exception e) {
350 print(e)
351 manager.buildFailure()
352 verify = -1
353 success = false
354 } finally {
355 print("Verifying status")
356 g = new Gerrit()
357 g.verifyStatus(verify, 'tf-m-build', 'build')
358 print("Generating build results summary.")
359 def build_results_for_summary = [:]
360 results['builds'].each { build ->
Xinyu Zhang0d85cc32022-10-19 17:58:32 +0800361 build_results_for_summary[build.key] = ['URL': build.value.getAbsoluteUrl(),
362 'RESULT': build.value.result]
Xinyu Zhang4b109802022-10-18 17:22:07 +0800363 }
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800364 emailNotification('build', build_results_for_summary)
Xinyu Zhang4b109802022-10-18 17:22:07 +0800365 writeCsv(build_results_for_summary, "build_results.csv")
366 writeHTML(build_results_for_summary, "build_links.html")
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800367 }
Xinyu Zhang6b456c22022-10-13 15:48:58 +0800368 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800369 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800370
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800371 stage("Tests") {
372 dir("tf-m-ci-scripts") {
373 checkout([$class: 'GitSCM', branches: [[name: '$CI_SCRIPTS_BRANCH']], userRemoteConfigs: [[credentialsId: 'GIT_SSH_KEY', url: '$CI_SCRIPTS_REPO']]])
374 }
375 def all_jobs = []
376 def success = true
Xinyu Zhang0f78e7a2022-10-17 13:55:52 +0800377 def test_results = [:]
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800378 print("Wait for LAVA results here...")
379 try {
380 all_jobs = submitJobsToList(results['lava_jobs'])
Paul Sokolovsky437bc422022-02-01 17:57:13 +0300381 output = ""
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800382 if (all_jobs.size() > 0) {
Paul Sokolovsky3d522f72022-04-13 11:17:00 +0300383 dir(".") {
Xinyu Zhang29a57cc2023-02-03 10:08:48 +0800384 if (isPerPatchJob()) {
385 lava_timeout = 2700 // 45min
386 } else {
Paul Sokolovsky288799c2023-03-20 21:19:58 +0700387 lava_timeout = 19800 // 5.5h
Xinyu Zhang29a57cc2023-02-03 10:08:48 +0800388 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800389 withCredentials([usernamePassword(credentialsId: env.LAVA_CREDENTIALS, passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) {
Xinyu Zhang0b84b632023-02-08 14:15:08 +0800390 sh(script: """./tf-m-ci-scripts/lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \
391 --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \
392 --artifacts-path cfgs --lava-timeout ${lava_timeout} > output.log
393 """)
Paul Sokolovsky0136de02022-04-19 20:21:47 +0300394 if (env.CODE_COVERAGE_EN == "TRUE") {
395 println("Producing merged report")
396 sh(script: """./tf-m-ci-scripts/lava_helper/codecov_merge.sh""")
397 archiveArtifacts artifacts: 'merged_report/**', allowEmptyArchive: true
398 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000399 }
400 }
401 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800402 else {
403 print("There were no LAVA jobs to test.")
404 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000405 }
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800406 catch (Exception e) {
Paul Sokolovsky2cf562a2022-12-02 15:10:58 +0300407 println("ERROR: ${e}")
408 // We don't print stacktrace, because Jenkins pipeline use CPS conversion
409 // of the Groovy code, which leads to incomprehensible stacktraces.
410 //print(hudson.Functions.printThrowable(org.codehaus.groovy.runtime.StackTraceUtils.sanitize(e)))
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800411 success = false
412 } finally {
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800413 if (all_jobs.size() > 0) {
Xinyu Zhang68858312023-02-23 11:11:09 +0800414 output = readFile("output.log")
415 println("--- output from lava_wait_jobs.py ---")
416 println(output)
417 println("--- end of output from lava_wait_jobs.py ---")
418 test_results = parseTestResults(output)
419 archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true
420 archiveArtifacts artifacts: 'cfgs/**', allowEmptyArchive: true
421 if (all_jobs.size() > 0) {
Xinyu Zhanga2a2c582023-03-03 14:21:47 +0800422 emailNotification('test', test_results)
Xinyu Zhang68858312023-02-23 11:11:09 +0800423 }
424 verifyTestStatus(output)
Xinyu Zhang4cdfd1b2021-05-21 15:10:49 +0800425 }
426 cleanWs()
427 if (!success) {
428 error("There was an Error waiting for LAVA jobs")
429 }
Matthew Hartfb6fd362020-03-04 21:03:59 +0000430 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000431 }
432 }
Dean Bircha6ede7e2020-03-13 14:00:33 +0000433}