Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 1 | #!/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 Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame^] | 9 | @Library('trustedfirmware') _ |
| 10 | import org.trustedfirmware.Gerrit |
| 11 | import org.trustedfirmware.Summary |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 12 | |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 13 | def 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 | |
| 25 | def 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 Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame^] | 42 | 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 Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 45 | 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 Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 49 | 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 Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | def buildDocs() { |
| 70 | def params = [] |
| 71 | params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH) |
Dean Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame^] | 72 | 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 Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 75 | 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 Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 82 | if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) { |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 83 | error("Build failed at ${res.getAbsoluteUrl()}") |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 88 | |
| 89 | def buildCsv(results) { |
Dean Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame^] | 90 | def summary = new Summary(); |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 91 | 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 | |
| 98 | def writeSummary(results) { |
Dean Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame^] | 99 | def summary = new Summary(); |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 100 | 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 Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 107 | def configs = [] |
| 108 | def builds = [:] |
| 109 | |
| 110 | node("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 Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 120 | results['builds'] = [:] |
| 121 | results['lava_jobs'] = [] |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 122 | for (config in configs) { |
| 123 | builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP) |
| 124 | } |
| 125 | builds["docs"] = buildDocs() |
| 126 | } |
| 127 | } |
| 128 | stage("Builds") { |
| 129 | def verify = 1 |
| 130 | try { |
| 131 | parallel(builds) |
| 132 | } catch (Exception e) { |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 133 | print(e) |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 134 | manager.buildFailure() |
| 135 | verify = -1 |
| 136 | } finally { |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 137 | print("Verifying status") |
Dean Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame^] | 138 | g = new Gerrit() |
| 139 | g.verifyStatus(verify, 'tf-m-build', 'build') |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 140 | print("Building CSV") |
| 141 | buildCsv(results['builds']) |
| 142 | writeSummary(results['builds']) |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 143 | } |
| 144 | } |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 145 | node("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 | } |