blob: e20b9a39ded85dbe1bcd76f7d126d21800ccfebb [file] [log] [blame]
Dean Birch62c4f082020-01-17 16:13:26 +00001#!/usr/bin/env groovy
2//-------------------------------------------------------------------------------
3// Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
4//
5// SPDX-License-Identifier: BSD-3-Clause
6//
7//-------------------------------------------------------------------------------
8
Dean Birchd0f9f8c2020-03-26 11:10:33 +00009@Library('trustedfirmware') _
10import org.trustedfirmware.Gerrit
11import org.trustedfirmware.Summary
Dean Bircha6ede7e2020-03-13 14:00:33 +000012
Dean Birch62c4f082020-01-17 16:13:26 +000013def listConfigs(ci_scripts_dir, config_list, filter_group) {
14 dir(ci_scripts_dir) {
15 echo "Obtaining list of configs."
16 echo "Running: ./configs.py -g ${filter_group}"
17 def build_config_list_raw = sh(script: """\
18./configs.py -g ${filter_group}
19""", returnStdout: true).trim()
20 def build_config_list = build_config_list_raw.tokenize('\n')
21 config_list.addAll(build_config_list)
22 }
23}
24
25def buildConfig(ci_scripts_dir, config, filter_group) {
26 def params = []
27 def build_config_params
28 dir(ci_scripts_dir) {
29 echo "Obtaining build configuration for config ${config}"
30 echo "Running: ./configs.py -g ${filter_group} ${config}"
31 build_config_params = sh(script: """\
32./configs.py -g ${filter_group} ${config}
33""", returnStdout: true).trim()
34 }
35 def lines = build_config_params.tokenize('\n')
36 for (String line : lines) {
37 def key, value
38 (key, value) = line.tokenize('=')
39 params += string(name: key, value: value)
40 }
41 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +000042 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
43 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
44 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +000045 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
46 params += string(name: 'CMSIS_VERSION', value: env.CMSIS_VERSION)
47 params += string(name: 'MBEDCRYPTO_VERSION', value: env.MBEDCRYPTO_VERSION)
48 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
Dean Bircha6ede7e2020-03-13 14:00:33 +000049 return { -> results
50 def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false)
51 def build_info = [build_res, config, params_collection]
52 results['builds'][build_res.number] = build_info
53 def build_url = build_res.getAbsoluteUrl()
54 print("${build_res.number}: ${config} ${build_res.result} ${build_url}")
55 failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]
56 if (build_res.result in failure_states) {
57 error("Build failed at ${build_url}")
58 }
59 else {
60 print("Doing LAVA stuff for ${build_url}")
61 params += string(name: 'BUILD_NUMBER', value: "${build_res.number}")
62 params += string(name: 'BUILD_URL', value: build_url)
63 def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false)
64 results['lava_jobs'] += lava_res.getDescription()
Dean Birch62c4f082020-01-17 16:13:26 +000065 }
66 }
67}
68
69def buildDocs() {
70 def params = []
71 params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH)
Dean Birchd0f9f8c2020-03-26 11:10:33 +000072 params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST)
73 params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER)
74 params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION)
Dean Birch62c4f082020-01-17 16:13:26 +000075 params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC)
76 params += string(name: 'CMSIS_VERSION', value: env.CMSIS_VERSION)
77 params += string(name: 'MBEDCRYPTO_VERSION', value: env.MBEDCRYPTO_VERSION)
78 params += string(name: 'CODE_REPO', value: env.CODE_REPO)
79 return {
80 def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false)
81 print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}")
Dean Bircha6ede7e2020-03-13 14:00:33 +000082 if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) {
Dean Birch62c4f082020-01-17 16:13:26 +000083 error("Build failed at ${res.getAbsoluteUrl()}")
84 }
85 }
86}
87
Dean Bircha6ede7e2020-03-13 14:00:33 +000088
89def buildCsv(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +000090 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +000091 def csvContent = summary.getBuildCsv(results)
92 node("master") {
93 writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL
94 archiveArtifacts 'build_results.csv'
95 }
96}
97
98def writeSummary(results) {
Dean Birchd0f9f8c2020-03-26 11:10:33 +000099 def summary = new Summary();
Dean Bircha6ede7e2020-03-13 14:00:33 +0000100 def buildLinks = summary.getLinks(results)
101 node("master") {
102 writeFile file: "build_links.html", text: buildLinks
103 archiveArtifacts 'build_links.html'
104 }
105}
106
Dean Birch62c4f082020-01-17 16:13:26 +0000107def configs = []
108def builds = [:]
109
110node("master") {
111 stage("Init") {
112 cleanWs()
113 dir("tf-m-ci-scripts") {
114 git url: '$CI_SCRIPTS_REPO', branch: 'master', credentialsId: 'GIT_SSH_KEY'
115 }
116 }
117 stage("Configs") {
118 // Populate configs
119 listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP)
Dean Bircha6ede7e2020-03-13 14:00:33 +0000120 results['builds'] = [:]
121 results['lava_jobs'] = []
Dean Birch62c4f082020-01-17 16:13:26 +0000122 for (config in configs) {
123 builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP)
124 }
125 builds["docs"] = buildDocs()
126 }
127}
128stage("Builds") {
129 def verify = 1
130 try {
131 parallel(builds)
132 } catch (Exception e) {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000133 print(e)
Dean Birch62c4f082020-01-17 16:13:26 +0000134 manager.buildFailure()
135 verify = -1
136 } finally {
Dean Bircha6ede7e2020-03-13 14:00:33 +0000137 print("Verifying status")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000138 g = new Gerrit()
139 g.verifyStatus(verify, 'tf-m-build', 'build')
Dean Bircha6ede7e2020-03-13 14:00:33 +0000140 print("Building CSV")
141 buildCsv(results['builds'])
142 writeSummary(results['builds'])
Dean Birch62c4f082020-01-17 16:13:26 +0000143 }
144}
Dean Bircha6ede7e2020-03-13 14:00:33 +0000145node("docker-amd64-xenial") {
146 stage("Tests") {
147 dir("tf-m-ci-scripts") {
148 git url: '$CI_SCRIPTS_REPO', branch: 'master', credentialsId: 'GIT_SSH_KEY'
149 }
150 print("Wait for LAVA results here...")
151 results['lava_jobs'].each { result ->
152 print(result)
153 }
154 }
155 cleanWs()
156}