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 | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame^] | 9 | library identifier: 'local-lib@master', retriever: legacySCM(scm) |
| 10 | |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 11 | def listConfigs(ci_scripts_dir, config_list, filter_group) { |
| 12 | dir(ci_scripts_dir) { |
| 13 | echo "Obtaining list of configs." |
| 14 | echo "Running: ./configs.py -g ${filter_group}" |
| 15 | def build_config_list_raw = sh(script: """\ |
| 16 | ./configs.py -g ${filter_group} |
| 17 | """, returnStdout: true).trim() |
| 18 | def build_config_list = build_config_list_raw.tokenize('\n') |
| 19 | config_list.addAll(build_config_list) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | def buildConfig(ci_scripts_dir, config, filter_group) { |
| 24 | def params = [] |
| 25 | def build_config_params |
| 26 | dir(ci_scripts_dir) { |
| 27 | echo "Obtaining build configuration for config ${config}" |
| 28 | echo "Running: ./configs.py -g ${filter_group} ${config}" |
| 29 | build_config_params = sh(script: """\ |
| 30 | ./configs.py -g ${filter_group} ${config} |
| 31 | """, returnStdout: true).trim() |
| 32 | } |
| 33 | def lines = build_config_params.tokenize('\n') |
| 34 | for (String line : lines) { |
| 35 | def key, value |
| 36 | (key, value) = line.tokenize('=') |
| 37 | params += string(name: key, value: value) |
| 38 | } |
| 39 | params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH) |
| 40 | params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC) |
| 41 | params += string(name: 'CMSIS_VERSION', value: env.CMSIS_VERSION) |
| 42 | params += string(name: 'MBEDCRYPTO_VERSION', value: env.MBEDCRYPTO_VERSION) |
| 43 | params += string(name: 'CODE_REPO', value: env.CODE_REPO) |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame^] | 44 | return { -> results |
| 45 | def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false) |
| 46 | def build_info = [build_res, config, params_collection] |
| 47 | results['builds'][build_res.number] = build_info |
| 48 | def build_url = build_res.getAbsoluteUrl() |
| 49 | print("${build_res.number}: ${config} ${build_res.result} ${build_url}") |
| 50 | failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"] |
| 51 | if (build_res.result in failure_states) { |
| 52 | error("Build failed at ${build_url}") |
| 53 | } |
| 54 | else { |
| 55 | print("Doing LAVA stuff for ${build_url}") |
| 56 | params += string(name: 'BUILD_NUMBER', value: "${build_res.number}") |
| 57 | params += string(name: 'BUILD_URL', value: build_url) |
| 58 | def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false) |
| 59 | results['lava_jobs'] += lava_res.getDescription() |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | def buildDocs() { |
| 65 | def params = [] |
| 66 | params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH) |
| 67 | params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC) |
| 68 | params += string(name: 'CMSIS_VERSION', value: env.CMSIS_VERSION) |
| 69 | params += string(name: 'MBEDCRYPTO_VERSION', value: env.MBEDCRYPTO_VERSION) |
| 70 | params += string(name: 'CODE_REPO', value: env.CODE_REPO) |
| 71 | return { |
| 72 | def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false) |
| 73 | print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}") |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame^] | 74 | if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) { |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 75 | error("Build failed at ${res.getAbsoluteUrl()}") |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame^] | 80 | |
| 81 | def buildCsv(results) { |
| 82 | def csvContent = summary.getBuildCsv(results) |
| 83 | node("master") { |
| 84 | writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL |
| 85 | archiveArtifacts 'build_results.csv' |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | def writeSummary(results) { |
| 90 | def buildLinks = summary.getLinks(results) |
| 91 | node("master") { |
| 92 | writeFile file: "build_links.html", text: buildLinks |
| 93 | archiveArtifacts 'build_links.html' |
| 94 | } |
| 95 | } |
| 96 | |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 97 | def verifyStatus(value, stage_name) { |
| 98 | node("docker-amd64-xenial") { |
| 99 | cleanWs() |
| 100 | dir("tf-m-ci-scripts") { |
| 101 | git url: '$CI_SCRIPTS_REPO', branch: 'master', credentialsId: 'GIT_SSH_KEY' |
| 102 | } |
| 103 | withCredentials([usernamePassword(credentialsId: 'VERIFY_STATUS', passwordVariable: 'VERIFY_PASSWORD', usernameVariable: 'VERIFY_USER')]) { |
| 104 | sh(""" |
| 105 | if [ -z "\$GERRIT_HOST" ] ; then |
| 106 | echo Not running for a Gerrit change, skipping vote. |
| 107 | exit 0 |
| 108 | fi |
| 109 | if [ ! -d venv ] ; then |
| 110 | virtualenv -p \$(which python3) venv |
| 111 | fi |
| 112 | . venv/bin/activate |
| 113 | pip -q install requests |
| 114 | ./tf-m-ci-scripts/jenkins/verify.py --value ${value} --verify-name tf-m-${stage_name} --user \$VERIFY_USER |
| 115 | """) |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | def configs = [] |
| 121 | def builds = [:] |
| 122 | |
| 123 | node("master") { |
| 124 | stage("Init") { |
| 125 | cleanWs() |
| 126 | dir("tf-m-ci-scripts") { |
| 127 | git url: '$CI_SCRIPTS_REPO', branch: 'master', credentialsId: 'GIT_SSH_KEY' |
| 128 | } |
| 129 | } |
| 130 | stage("Configs") { |
| 131 | // Populate configs |
| 132 | listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP) |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame^] | 133 | results['builds'] = [:] |
| 134 | results['lava_jobs'] = [] |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 135 | for (config in configs) { |
| 136 | builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP) |
| 137 | } |
| 138 | builds["docs"] = buildDocs() |
| 139 | } |
| 140 | } |
| 141 | stage("Builds") { |
| 142 | def verify = 1 |
| 143 | try { |
| 144 | parallel(builds) |
| 145 | } catch (Exception e) { |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame^] | 146 | print(e) |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 147 | manager.buildFailure() |
| 148 | verify = -1 |
| 149 | } finally { |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame^] | 150 | print("Verifying status") |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 151 | verifyStatus(verify, 'build') |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame^] | 152 | print("Building CSV") |
| 153 | buildCsv(results['builds']) |
| 154 | writeSummary(results['builds']) |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame^] | 157 | node("docker-amd64-xenial") { |
| 158 | stage("Tests") { |
| 159 | dir("tf-m-ci-scripts") { |
| 160 | git url: '$CI_SCRIPTS_REPO', branch: 'master', credentialsId: 'GIT_SSH_KEY' |
| 161 | } |
| 162 | print("Wait for LAVA results here...") |
| 163 | results['lava_jobs'].each { result -> |
| 164 | print(result) |
| 165 | } |
| 166 | } |
| 167 | cleanWs() |
| 168 | } |