blob: 5e49365db4d9ee4f7515eb280ab8316ee9935770 [file] [log] [blame]
vnaumov33747e12020-05-04 17:35:20 +02001package com.mirantis.mk
vnaumov33747e12020-05-04 17:35:20 +02002
3/**
4 *
5 * KaaS Component Testing Utilities
6 *
7 */
8
Владислав Наумовe5345812020-08-12 16:30:20 +02009/**
10 * Check KaaS Core CICD feature flags
11 * such triggers can be used in case of switching between pipelines,
12 * conditions inside pipelines to reduce dependency on jenkins job builder and jenkins job templates itself
13 *
14 * @return (map)[
15 * ffNameEnabled: (bool) True/False
16 * ]
17 */
18def checkCoreCIFeatureFlags() {
19 def common = new com.mirantis.mk.Common()
20 def ff = [
21 build_artifacts_upgrade: false,
22 ]
23
24 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
25 if (commitMsg ==~ /(?s).*\[ci-build-artifacts-upgrade\].*/) {
26 ff['build_artifacts_upgrade'] = true
27 }
28
29 common.infoMsg("Core ci feature flags status: ${ff}")
30 return ff
31}
vnaumov33747e12020-05-04 17:35:20 +020032
33/**
azvyagintseva12230a2020-06-05 13:24:06 +030034 * Determine scope of test suite against per-commit KaaS deployment based on keywords
Владислав Наумов81777472021-03-09 15:14:27 +040035 * Keyword list: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md
azvyagintseva12230a2020-06-05 13:24:06 +030036 *
37 * Used for components team to combine test-suites and forward desired parameters to kaas/core deployment jobs
38 * Example scheme:
Владислав Наумовe5345812020-08-12 16:30:20 +020039 * New CR pushed in kubernetes/lcm-ansible -> parsing it'cs commit body and combine test-suite -> trigger deployment jobs from kaas/core
azvyagintseva12230a2020-06-05 13:24:06 +030040 * manage test-suite through Jenkins Job Parameters
41 *
Владислав Наумов6c2afff2020-06-05 12:54:53 +020042 * @return (map)[
43 * deployChildEnabled: (bool) True if need to deploy child cluster during demo-run
44 * runUie2eEnabled: (bool) True if need to run ui-e2e cluster during demo-run
azvyagintseva12230a2020-06-05 13:24:06 +030045 * ]
46 */
vnaumov33747e12020-05-04 17:35:20 +020047def checkDeploymentTestSuite() {
vnaumovbdb90222020-05-04 18:25:50 +020048 def common = new com.mirantis.mk.Common()
49
vnaumov33747e12020-05-04 17:35:20 +020050 // Available triggers and its sane defaults
Владислав Наумов44c64b72020-12-04 20:22:53 +010051 def seedMacOs = env.SEED_MACOS ? env.SEED_MACOS.toBoolean() : false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020052 def deployChild = env.DEPLOY_CHILD_CLUSTER ? env.DEPLOY_CHILD_CLUSTER.toBoolean() : false
53 def upgradeChild = env.UPGRADE_CHILD_CLUSTER ? env.UPGRADE_CHILD_CLUSTER.toBoolean() : false
Mikhail Ivanov38ee4382022-01-27 16:21:51 +040054 def mosDeployChild = env.DEPLOY_MOS_CHILD_CLUSTER ? env.DEPLOY_MOS_CHILD_CLUSTER.toBoolean() : false
55 def mosUpgradeChild = env.UPGRADE_MOS_CHILD_CLUSTER ? env.UPGRADE_MOS_CHILD_CLUSTER.toBoolean() : false
Mikhail Ivanov74504372021-05-21 17:01:06 +040056 def customChildRelease = env.KAAS_CHILD_CLUSTER_RELEASE_NAME ? env.KAAS_CHILD_CLUSTER_RELEASE_NAME : ''
slalov021171f2022-03-04 14:48:38 +040057 def mosTfDeploy = env.MOS_TF_DEPLOY ? env.MOS_TF_DEPLOY.toBoolean() : false
Владислав Наумов0dc99252020-11-13 13:30:48 +010058 def attachBYO = env.ATTACH_BYO ? env.ATTACH_BYO.toBoolean() : false
Владислав Наумовcdbd84e2020-12-01 16:51:09 +010059 def upgradeBYO = env.UPGRADE_BYO ? env.UPGRADE_BYO.toBoolean() : false
Vladislav Naumov7930ab22021-11-22 18:24:24 +010060 def runBYOMatrix = env.RUN_BYO_MATRIX ? env.RUN_BYO_MATRIX.toBoolean() : false
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +040061 def defaultBYOOs = env.DEFAULT_BYO_OS ? env.DEFAULT_BYO_OS.toString() : 'ubuntu'
Владислав Наумов6c2afff2020-06-05 12:54:53 +020062 def upgradeMgmt = env.UPGRADE_MGMT_CLUSTER ? env.UPGRADE_MGMT_CLUSTER.toBoolean() : false
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +040063 def enableLMALogging = env.ENABLE_LMA_LOGGING ? env.ENABLE_LMA_LOGGING.toBoolean(): false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020064 def runUie2e = env.RUN_UI_E2E ? env.RUN_UI_E2E.toBoolean() : false
Mikhail Ivanovf5e20af2022-03-24 15:38:06 +040065 def runUie2eNew = env.RUN_UI_E2E_NEW ? env.RUN_UI_E2E_NEW.toBoolean() : false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020066 def runMgmtConformance = env.RUN_MGMT_CFM ? env.RUN_MGMT_CFM.toBoolean() : false
Владислав Наумов9cec55d2021-08-03 15:00:59 +020067 def runLMATest = env.RUN_LMA_TEST ? env.RUN_LMA_TEST.toBoolean() : false
Vladyslav Drokc4f9c1b2021-07-22 15:34:24 +020068 def runMgmtUserControllerTest = env.RUN_MGMT_USER_CONTROLLER_TEST ? env.RUN_MGMT_USER_CONTROLLER_TEST.toBoolean() : false
Mikhail Ivanov2907e4d2022-04-25 16:41:21 +040069 def runProxyChildTest = env.RUN_PROXY_CHILD_TEST ? env.RUN_PROXY_CHILD_TEST.toBoolean() : false
Владислав Наумов6c2afff2020-06-05 12:54:53 +020070 def runChildConformance = env.RUN_CHILD_CFM ? env.RUN_CHILD_CFM.toBoolean() : false
71 def fetchServiceBinaries = env.FETCH_BINARIES_FROM_UPSTREAM ? env.FETCH_BINARIES_FROM_UPSTREAM.toBoolean() : false
Vladislav Naumov42b71dc2021-11-22 13:09:42 +010072 def equinixMetalV2ChildDiffMetro = env.EQUINIXMETALV2_CHILD_DIFF_METRO ? env.EQUINIXMETALV2_CHILD_DIFF_METRO.toBoolean() : false
slalov13e579c2022-01-31 21:37:02 +040073 def runMaintenanceTest = env.RUN_MAINTENANCE_TEST ? env.RUN_MAINTENANCE_TEST.toBoolean() : false
Владислав Наумов765f3bd2020-09-07 18:09:24 +020074 // multiregion configuration from env variable: comma-separated string in form $mgmt_provider,$regional_provider
75 def multiregionalMappings = env.MULTIREGION_SETUP ? multiregionWorkflowParser(env.MULTIREGION_SETUP) : [
76 enabled: false,
77 managementLocation: '',
78 regionLocation: '',
79 ]
Владислав Наумов4eb1da32020-08-31 14:45:16 +020080
Владислав Наумовb8305e22021-02-10 17:23:12 +010081 // proxy customization
82 def proxyConfig = [
Владислав Наумовf8f23fa2021-04-01 16:57:52 +020083 mgmtOffline: env.OFFLINE_MGMT_CLUSTER ? env.OFFLINE_MGMT_CLUSTER.toBoolean() : false,
84 childOffline: env.OFFLINE_CHILD_CLUSTER ? env.OFFLINE_CHILD_CLUSTER.toBoolean() : false,
Владислав Наумов257ea132021-04-14 14:44:13 +020085 childProxy: env.PROXY_CHILD_CLUSTER ? env.PROXY_CHILD_CLUSTER.toBoolean() : false,
Владислав Наумовb8305e22021-02-10 17:23:12 +010086 ]
87
Владислав Наумов4eb1da32020-08-31 14:45:16 +020088 // optional demo deployment customization
Владислав Наумов905dd362020-06-08 16:37:01 +020089 def awsOnDemandDemo = env.ALLOW_AWS_ON_DEMAND ? env.ALLOW_AWS_ON_DEMAND.toBoolean() : false
Владислав Наумовe021b022021-05-06 11:26:38 +020090 def equinixOnDemandDemo = env.ALLOW_EQUINIX_ON_DEMAND ? env.ALLOW_EQUINIX_ON_DEMAND.toBoolean() : false
Владислав Наумов82305e92021-10-14 20:45:20 +020091 def equinixMetalV2OnDemandDemo = env.ALLOW_EQUINIXMETALV2_ON_DEMAND ? env.ALLOW_EQUINIXMETALV2_ON_DEMAND.toBoolean() : false
Владислав Наумовf3715802021-05-03 18:06:45 +020092 def equinixOnAwsDemo = env.EQUINIX_ON_AWS_DEMO ? env.EQUINIX_ON_AWS_DEMO.toBoolean() : false
Владислав Наумов2d3db332021-06-15 15:19:19 +020093 def azureOnAwsDemo = env.AZURE_ON_AWS_DEMO ? env.AZURE_ON_AWS_DEMO.toBoolean() : false
Владислав Наумовc52dd9d2021-06-28 16:27:29 +020094 def azureOnDemandDemo = env.ALLOW_AZURE_ON_DEMAND ? env.ALLOW_AZURE_ON_DEMAND.toBoolean() : false
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +040095 def enableVsphereDemo = true
Владислав Наумов4eb1da32020-08-31 14:45:16 +020096 def enableOSDemo = true
azvyagintsev1761bdc2020-09-04 17:24:12 +030097 def enableBMDemo = true
Mikhail Ivanovbd1a9fd2022-03-29 21:36:21 +040098 def enableArtifactsBuild = true
Mikhail Ivanovb6283f72021-11-24 18:34:57 +040099 def openstackIMC = env.OPENSTACK_CLOUD_LOCATION ? env.OPENSTACK_CLOUD_LOCATION : 'us'
Alexandr Lovtsov36473f32022-04-28 15:46:09 +0300100 def enableVsphereUbuntu = env.VSPHERE_DEPLOY_UBUNTU ? env.VSPHERE_DEPLOY_UBUNTU.toBoolean() : false
vnaumov33747e12020-05-04 17:35:20 +0200101
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200102 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
Владислав Наумовb8305e22021-02-10 17:23:12 +0100103 if (commitMsg ==~ /(?s).*\[mgmt-proxy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-proxy.*/) {
104 proxyConfig['mgmtOffline'] = true
Владислав Наумов70c02422021-04-19 14:29:41 +0200105 common.warningMsg('Forced running offline mgmt deployment, some provider CDN regions for mgmt deployment may be set to *public-ci* to verify proxy configuration')
Владислав Наумовb8305e22021-02-10 17:23:12 +0100106 }
Владислав Наумов44c64b72020-12-04 20:22:53 +0100107 if (commitMsg ==~ /(?s).*\[seed-macos\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*seed-macos.*/) {
108 seedMacOs = true
109 }
slalov574123e2022-04-06 17:24:19 +0400110 if (commitMsg ==~ /(?s).*\[child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-deploy.*/ || upgradeChild || runChildConformance || runProxyChildTest) {
vnaumov33747e12020-05-04 17:35:20 +0200111 deployChild = true
112 }
113 if (commitMsg ==~ /(?s).*\[child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-upgrade.*/) {
114 deployChild = true
115 upgradeChild = true
116 }
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400117 def childDeployMatches = (commitMsg =~ /(\[child-deploy\s*(\w|\-)+?\])/)
118 if (childDeployMatches.size() > 0) {
Mikhail Ivanov74504372021-05-21 17:01:06 +0400119 // override child version when it set explicitly
120 deployChild = true
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400121 customChildRelease = childDeployMatches[0][0].split('child-deploy')[1].replaceAll('[\\[\\]]', '').trim()
Mikhail Ivanov74504372021-05-21 17:01:06 +0400122 common.warningMsg("Forced child deployment using custom release version ${customChildRelease}")
123 }
Mikhail Ivanov38ee4382022-01-27 16:21:51 +0400124 if (commitMsg ==~ /(?s).*\[mos-child-deploy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mos-child-deploy.*/) {
125 mosDeployChild = true
126 }
127 if (commitMsg ==~ /(?s).*\[mos-child-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mos-child-upgrade.*/) {
128 mosDeployChild = true
129 mosUpgradeChild = true
130 }
Владислав Наумов0dc99252020-11-13 13:30:48 +0100131 if (commitMsg ==~ /(?s).*\[byo-attach\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-attach.*/) {
132 attachBYO = true
133 }
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100134 if (commitMsg ==~ /(?s).*\[byo-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*byo-upgrade.*/) {
135 attachBYO = true
136 upgradeBYO = true
137 }
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400138
139 def byoDeployMatches = (commitMsg =~ /(\[run-byo-matrix\s*(ubuntu|centos)\])/)
140 if (commitMsg ==~ /(?s).*\[run-byo-matrix\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*run-byo-matrix\.*/ || byoDeployMatches.size() > 0) {
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100141 runBYOMatrix = true
142
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400143 if (byoDeployMatches.size() > 0) {
144 defaultBYOOs = byoDeployMatches[0][2]
145 common.warningMsg("Custom BYO OS detected, using ${defaultBYOOs}")
146 }
147
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100148 common.warningMsg('Forced byo matrix test via run-byo-matrix, all other byo triggers will be skipped')
149 attachBYO = false
150 upgradeBYO = false
151 }
Владислав Наумов7f8c9872021-03-08 17:33:08 +0400152 if (commitMsg ==~ /(?s).*\[mgmt-upgrade\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-upgrade.*/) {
vnaumov33747e12020-05-04 17:35:20 +0200153 upgradeMgmt = true
154 }
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +0400155 if (commitMsg ==~ /(?s).*\[lma-logging\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*lma-logging.*/) {
156 enableLMALogging = true
157 }
vnaumov33747e12020-05-04 17:35:20 +0200158 if (commitMsg ==~ /(?s).*\[ui-e2e\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e.*/) {
159 runUie2e = true
160 }
Mikhail Ivanovf5e20af2022-03-24 15:38:06 +0400161 if (commitMsg ==~ /(?s).*\[ui-e2e-new\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*ui-e2e-new.*/) {
162 runUie2eNew = true
163 }
vnaumov33747e12020-05-04 17:35:20 +0200164 if (commitMsg ==~ /(?s).*\[mgmt-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mgmt-cfm.*/) {
165 runMgmtConformance = true
166 }
Vladyslav Drokc4f9c1b2021-07-22 15:34:24 +0200167 if (commitMsg ==~ /(?s).*\[test-user-controller\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*test-user-controller.*/) {
168 runMgmtUserControllerTest = true
169 }
slalov574123e2022-04-06 17:24:19 +0400170 if (commitMsg ==~ /(?s).*\[test-proxy-child\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*test-proxy-child.*/) {
171 runProxyChildTest = true
172 deployChild = true
173 common.infoMsg('Child cluster deployment will be enabled since proxy child test suite will be executed')
174 }
vnaumov33747e12020-05-04 17:35:20 +0200175 if (commitMsg ==~ /(?s).*\[child-cfm\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-cfm.*/) {
176 runChildConformance = true
177 deployChild = true
178 }
Владислав Наумов9cec55d2021-08-03 15:00:59 +0200179 if (commitMsg ==~ /(?s).*\[lma-test\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*lma-test.*/) {
180 runLMATest = true
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +0400181 enableLMALogging = true
182 common.infoMsg('LMA logging will be enabled since LMA test suite will be executed')
Victor Ryzhenkin15206592021-06-21 17:38:23 +0400183 }
slalov13e579c2022-01-31 21:37:02 +0400184 if (commitMsg ==~ /(?s).*\[maintenance-test\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*maintenance-test.*/) {
185 runMaintenanceTest = true
186 }
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200187 if (commitMsg ==~ /(?s).*\[child-offline\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-offline.*/) {
188 proxyConfig['childOffline'] = true
189 deployChild = true
190 }
Владислав Наумов257ea132021-04-14 14:44:13 +0200191 if (commitMsg ==~ /(?s).*\[child-proxy\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*child-proxy.*/) {
192 proxyConfig['childOffline'] = true
193 proxyConfig['childProxy'] = true
194 deployChild = true
195 }
vnaumov33747e12020-05-04 17:35:20 +0200196 if (commitMsg ==~ /(?s).*\[fetch.*binaries\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*fetch.*binaries.*/) {
197 fetchServiceBinaries = true
198 }
Владислав Наумовf1665b52021-05-13 10:51:17 +0200199 if (commitMsg ==~ /(?s).*\[equinix-on-aws\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinix-on-aws.*/) {
eromanovadf247c32020-12-25 15:44:13 +0400200 equinixOnAwsDemo = true
Владислав Наумовf1665b52021-05-13 10:51:17 +0200201 common.warningMsg('Forced running child cluster deployment on EQUINIX METAL provider based on AWS management cluster, triggered on patchset using custom keyword: \'[equinix-on-aws]\' ')
eromanovadf247c32020-12-25 15:44:13 +0400202 }
Владислав Наумов2d3db332021-06-15 15:19:19 +0200203 if (commitMsg ==~ /(?s).*\[azure-on-aws\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*azure-on-aws.*/) {
204 azureOnAwsDemo = true
205 common.warningMsg('Forced running child cluster deployment on Azure provider based on AWS management cluster, triggered on patchset using custom keyword: \'[azure-on-aws]\' ')
206 }
207 if (commitMsg ==~ /(?s).*\[aws-demo\].*/ ||
208 env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*aws-demo.*/ ||
209 attachBYO ||
210 upgradeBYO ||
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100211 runBYOMatrix ||
Владислав Наумов2d3db332021-06-15 15:19:19 +0200212 seedMacOs ||
213 equinixOnAwsDemo ||
214 azureOnAwsDemo) {
215
vnaumov33747e12020-05-04 17:35:20 +0200216 awsOnDemandDemo = true
Владислав Наумов2d3db332021-06-15 15:19:19 +0200217 common.warningMsg('Running additional kaas deployment with AWS provider, may be forced due applied trigger cross dependencies, follow docs to clarify info')
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200218 }
Владислав Наумовf1665b52021-05-13 10:51:17 +0200219 if (commitMsg ==~ /(?s).*\[equinix-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinix-demo\.*/) {
Владислав Наумовe021b022021-05-06 11:26:38 +0200220 equinixOnDemandDemo = true
221 }
Владислав Наумов82305e92021-10-14 20:45:20 +0200222 if (commitMsg ==~ /(?s).*\[equinixmetalv2-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinixmetalv2-demo\.*/) {
Владислав Наумов144956f2021-10-14 17:49:19 +0200223 equinixMetalV2OnDemandDemo = true
224 }
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100225 if (commitMsg ==~ /(?s).*\[equinixmetalv2-child-diff-metro\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*equinixmetalv2-child-diff-metro\.*/) {
226 equinixMetalV2OnDemandDemo = true
227 equinixMetalV2ChildDiffMetro = true
228 }
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200229 if (commitMsg ==~ /(?s).*\[azure-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*azure-demo\.*/) {
230 azureOnDemandDemo = true
231 }
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200232 if (commitMsg ==~ /(?s).*\[disable-os-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-os-demo\.*/) {
233 enableOSDemo = false
234 common.errorMsg('Openstack demo deployment will be aborted, VF -1 will be set')
vnaumov33747e12020-05-04 17:35:20 +0200235 }
236
azvyagintsev1761bdc2020-09-04 17:24:12 +0300237 if (commitMsg ==~ /(?s).*\[disable-bm-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-bm-demo\.*/) {
238 enableBMDemo = false
239 common.errorMsg('BM demo deployment will be aborted, VF -1 will be set')
240 }
241
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400242 if (commitMsg ==~ /(?s).*\[disable-vsphere-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-vsphere-demo\.*/) {
243 enableVsphereDemo = false
244 common.errorMsg('vSphere demo deployment will be aborted, VF -1 will be set')
245 }
Alexandr Lovtsov36473f32022-04-28 15:46:09 +0300246 if (commitMsg ==~ /(?s).*\[vsphere-ubuntu\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*vsphere-ubuntu\.*/) {
247 enableVsphereUbuntu = true
248 common.warningMsg('Ubuntu will be used to deploy vsphere machines')
249 }
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400250
Mikhail Ivanovbd1a9fd2022-03-29 21:36:21 +0400251 if (commitMsg ==~ /(?s).*\[disable-artifacts-build\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*disable-artifacts-build\.*/) {
252 enableArtifactsBuild = false
253 common.errorMsg('artifacts build will be aborted, VF -1 will be set')
254 }
255
vnaumov33747e12020-05-04 17:35:20 +0200256 // TODO (vnaumov) remove below condition after moving all releases to UCP
257 def ucpChildMatches = (commitMsg =~ /(\[child-ucp\s*ucp-.*?\])/)
258 if (ucpChildMatches.size() > 0) {
259 deployChild = true
260 common.warningMsg('Forced UCP based child deployment triggered on patchset using custom keyword: \'[child-ucp ucp-5-1-0-3-3-0-example]\' ')
261
262 // TODO(vnaumov) delete after ucp upgrades support
263 common.errorMsg('Child upgrade test will be skipped, UCP upgrades temporally disabled')
264 upgradeChild = false
265 }
266
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200267 // multiregional tests
268 def multiRegionalMatches = (commitMsg =~ /(\[multiregion\s*.*?\])/)
269 if (multiRegionalMatches.size() > 0) {
270 multiregionalMappings = multiregionWorkflowParser(multiRegionalMatches)
271 }
272 switch (multiregionalMappings['managementLocation']) {
273 case 'aws':
Владислав Наумов53b07e52021-01-07 15:08:27 +0100274 common.warningMsg('Forced running additional kaas deployment with AWS provider according multiregional demo request')
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200275 awsOnDemandDemo = true
Владислав Наумов53b07e52021-01-07 15:08:27 +0100276
277 if (multiregionalMappings['regionLocation'] != 'aws' && seedMacOs) { // macstadium seed node has access only to *public* providers
278 error('incompatible triggers: [seed-macos] and multiregional deployment based on *private* regional provider cannot be applied simultaneously')
279 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200280 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200281 case 'os':
282 if (enableOSDemo == false) {
283 error('incompatible triggers: [disable-os-demo] and multiregional deployment based on OSt management region cannot be applied simultaneously')
284 }
Владислав Наумов3e4b5a32020-09-11 17:05:34 +0200285 break
Владислав Наумов865ba6c2021-05-13 13:05:45 +0200286 case 'vsphere':
287 if (enableVsphereDemo == false) {
288 error('incompatible triggers: [disable-vsphere-demo] and multiregional deployment based on Vsphere management region cannot be applied simultaneously')
289 }
290 break
Владислав Наумов5be02942021-05-13 12:34:37 +0200291 case 'equinix':
292 common.warningMsg('Forced running additional kaas deployment with Equinix provider according multiregional demo request')
293 equinixOnDemandDemo = true
eromanova35359162021-12-30 14:13:13 +0400294 break
eromanova8c702ae2021-12-24 17:43:12 +0400295 case 'equinixmetalv2':
296 common.warningMsg('Forced running additional kaas deployment with Equinix Metal V2 provider according multiregional demo request')
297 equinixMetalV2OnDemandDemo = true
eromanova35359162021-12-30 14:13:13 +0400298 break
slalovfd0b7e62021-07-28 18:05:16 +0400299 case 'azure':
300 common.warningMsg('Forced running additional kaas deployment with Azure provider according multiregional demo request')
301 azureOnDemandDemo = true
302 break
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200303 }
304
Владислав Наумовb8305e22021-02-10 17:23:12 +0100305 // CDN configuration
306 def cdnConfig = [
307 mgmt: [
308 openstack: (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-ci',
Владислав Наумов70c02422021-04-19 14:29:41 +0200309 vsphere: 'internal-ci',
Владислав Наумовb8305e22021-02-10 17:23:12 +0100310 aws: 'public-ci',
Владислав Наумовe021b022021-05-06 11:26:38 +0200311 equinix: 'public-ci',
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200312 azure: 'public-ci',
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200313 ],
Владислав Наумовb8305e22021-02-10 17:23:12 +0100314 ]
315
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400316 if (commitMsg ==~ /(?s).*\[eu-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*eu-demo.*/) {
317 openstackIMC = 'eu'
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400318 }
slalov021171f2022-03-04 14:48:38 +0400319 if (commitMsg ==~ /(?s).*\[mos-tf-demo\].*/ || env.GERRIT_EVENT_COMMENT_TEXT ==~ /(?s).*mos-tf-demo.*/) {
320 openstackIMC = 'eu2'
Mikhail Ivanovf05b8252022-04-27 18:14:03 +0400321 }
322 if (openstackIMC == 'eu' || openstackIMC == 'eu2') {
slalov021171f2022-03-04 14:48:38 +0400323 // use internal-eu because on internal-ci with eu cloud image pull takes much time
324 def cdnRegion = (proxyConfig['mgmtOffline'] == true) ? 'public-ci' : 'internal-eu'
325 common.infoMsg("eu2-demo was triggered, force switching CDN region to ${cdnRegion}")
326 cdnConfig['mgmt']['openstack'] = cdnRegion
327 }
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400328
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100329 // calculate weight of current demo run to manage lockable resources
330 def demoWeight = (deployChild) ? 2 : 1 // management = 1, child = 1
331
vnaumov33747e12020-05-04 17:35:20 +0200332 common.infoMsg("""
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400333 OpenStack Cloud location: ${openstackIMC}
Владислав Наумовb8305e22021-02-10 17:23:12 +0100334 CDN deployment configuration: ${cdnConfig}
335 MCC offline deployment configuration: ${proxyConfig}
Владислав Наумов44c64b72020-12-04 20:22:53 +0100336 Use MacOS node as seed: ${seedMacOs}
vnaumov33747e12020-05-04 17:35:20 +0200337 Child cluster deployment scheduled: ${deployChild}
Mikhail Ivanov74504372021-05-21 17:01:06 +0400338 Custom child cluster release: ${customChildRelease}
vnaumov33747e12020-05-04 17:35:20 +0200339 Child cluster release upgrade scheduled: ${upgradeChild}
Mikhail Ivanov38ee4382022-01-27 16:21:51 +0400340 MOS child deploy scheduled: ${mosDeployChild}
341 MOS child upgrade scheduled: ${mosUpgradeChild}
vnaumov33747e12020-05-04 17:35:20 +0200342 Child conformance testing scheduled: ${runChildConformance}
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100343 Single BYO cluster attachment scheduled: ${attachBYO}
344 Single Attached BYO cluster upgrade test scheduled: ${upgradeBYO}
345 BYO test matrix whole suite scheduled: ${runBYOMatrix}
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400346 Default BYO OS: ${defaultBYOOs}
vnaumov33747e12020-05-04 17:35:20 +0200347 Mgmt cluster release upgrade scheduled: ${upgradeMgmt}
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +0400348 Mgmt LMA logging enabled: ${enableLMALogging}
vnaumov33747e12020-05-04 17:35:20 +0200349 Mgmt conformance testing scheduled: ${runMgmtConformance}
Владислав Наумов9cec55d2021-08-03 15:00:59 +0200350 LMA testing scheduled: ${runLMATest}
Vladyslav Drokc4f9c1b2021-07-22 15:34:24 +0200351 Mgmt user controller testing scheduled: ${runMgmtUserControllerTest}
vnaumov33747e12020-05-04 17:35:20 +0200352 Mgmt UI e2e testing scheduled: ${runUie2e}
Mikhail Ivanovf5e20af2022-03-24 15:38:06 +0400353 Mgmt UI e2e playwrite testing scheduled: ${runUie2eNew}
slalov13e579c2022-01-31 21:37:02 +0400354 Maintenance test: ${runMaintenanceTest}
slalov574123e2022-04-06 17:24:19 +0400355 Child proxy test: ${runProxyChildTest}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200356 AWS provider deployment scheduled: ${awsOnDemandDemo}
Владислав Наумовe021b022021-05-06 11:26:38 +0200357 Equinix provider deployment scheduled: ${equinixOnDemandDemo}
Владислав Наумов144956f2021-10-14 17:49:19 +0200358 EquinixmetalV2 provider deployment scheduled: ${equinixMetalV2OnDemandDemo}
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100359 EquinixmetalV2 child deploy in a separate metro scheduled: ${equinixMetalV2ChildDiffMetro}
Владислав Наумовf1665b52021-05-13 10:51:17 +0200360 Equinix@AWS child cluster deployment scheduled: ${equinixOnAwsDemo}
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200361 Azure provider deployment scheduled: ${azureOnDemandDemo}
Владислав Наумов2d3db332021-06-15 15:19:19 +0200362 Azure@AWS child cluster deployment scheduled: ${azureOnAwsDemo}
Ivan Berezovskiyf9bcfd62021-03-18 18:41:38 +0400363 VSPHERE provider deployment scheduled: ${enableVsphereDemo}
Владислав Наумов4eb1da32020-08-31 14:45:16 +0200364 OS provider deployment scheduled: ${enableOSDemo}
azvyagintsev1761bdc2020-09-04 17:24:12 +0300365 BM provider deployment scheduled: ${enableBMDemo}
Alexandr Lovtsov36473f32022-04-28 15:46:09 +0300366 Ubuntu on vSphere scheduled: ${enableVsphereUbuntu}
Mikhail Ivanovbd1a9fd2022-03-29 21:36:21 +0400367 Artifacts build scheduled: ${enableArtifactsBuild}
Владислав Наумовf793fe32020-09-11 15:19:19 +0200368 Multiregional configuration: ${multiregionalMappings}
vnaumov33747e12020-05-04 17:35:20 +0200369 Service binaries fetching scheduled: ${fetchServiceBinaries}
Владислав Наумов74e2d6e2020-12-30 17:05:40 +0100370 Current weight of the demo run: ${demoWeight} (Used to manage lockable resources)
Владислав Наумов81777472021-03-09 15:14:27 +0400371 Triggers: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
vnaumov33747e12020-05-04 17:35:20 +0200372 return [
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400373 osCloudLocation : openstackIMC,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100374 cdnConfig : cdnConfig,
375 proxyConfig : proxyConfig,
376 useMacOsSeedNode : seedMacOs,
377 deployChildEnabled : deployChild,
378 childDeployCustomRelease : customChildRelease,
379 upgradeChildEnabled : upgradeChild,
Mikhail Ivanov38ee4382022-01-27 16:21:51 +0400380 mosDeployChildEnabled : mosDeployChild,
381 mosUpgradeChildEnabled : mosUpgradeChild,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100382 runChildConformanceEnabled : runChildConformance,
383 attachBYOEnabled : attachBYO,
384 upgradeBYOEnabled : upgradeBYO,
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100385 runBYOMatrixEnabled : runBYOMatrix,
Mikhail Ivanoveabc9d92021-12-30 16:40:14 +0400386 defaultBYOOs : defaultBYOOs,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100387 upgradeMgmtEnabled : upgradeMgmt,
388 enableLMALoggingEnabled : enableLMALogging,
389 runUie2eEnabled : runUie2e,
Mikhail Ivanovf5e20af2022-03-24 15:38:06 +0400390 runUie2eNewEnabled : runUie2eNew,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100391 runMgmtConformanceEnabled : runMgmtConformance,
slalov13e579c2022-01-31 21:37:02 +0400392 runMaintenanceTestEnable : runMaintenanceTest,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100393 runLMATestEnabled : runLMATest,
394 runMgmtUserControllerTestEnabled : runMgmtUserControllerTest,
slalov574123e2022-04-06 17:24:19 +0400395 runProxyChildTestEnabled : runProxyChildTest,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100396 fetchServiceBinariesEnabled : fetchServiceBinaries,
397 awsOnDemandDemoEnabled : awsOnDemandDemo,
398 equinixOnDemandDemoEnabled : equinixOnDemandDemo,
399 equinixMetalV2OnDemandDemoEnabled : equinixMetalV2OnDemandDemo,
400 equinixMetalV2ChildDiffMetroEnabled : equinixMetalV2ChildDiffMetro,
401 equinixOnAwsDemoEnabled : equinixOnAwsDemo,
402 azureOnDemandDemoEnabled : azureOnDemandDemo,
403 azureOnAwsDemoEnabled : azureOnAwsDemo,
404 vsphereDemoEnabled : enableVsphereDemo,
405 vsphereOnDemandDemoEnabled : enableVsphereDemo, // TODO: remove after MCC 2.7 is out
406 bmDemoEnabled : enableBMDemo,
407 osDemoEnabled : enableOSDemo,
Alexandr Lovtsov36473f32022-04-28 15:46:09 +0300408 vsphereUbuntuEnabled : enableVsphereUbuntu,
Mikhail Ivanovbd1a9fd2022-03-29 21:36:21 +0400409 artifactsBuildEnabled : enableArtifactsBuild,
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100410 multiregionalConfiguration : multiregionalMappings,
411 demoWeight : demoWeight]
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200412}
413
414/**
415 * Determine management and regional setup for demo workflow scenario
416 *
417 *
418 * @param: keyword (string) string , represents keyworkd trigger, specified in gerrit commit body, like `[multiregion aws,os]`
419 or Jenkins environment string variable in form like 'aws,os'
420 * @return (map)[
421 enabled: (bool),
422 * managementLocation: (string), //aws,os
423 * regionLocation: (string), //aws,os
424 * ]
425 */
426def multiregionWorkflowParser(keyword) {
Владислав Наумов8c0c39d2020-09-11 14:46:48 +0200427 def common = new com.mirantis.mk.Common()
eromanova8c702ae2021-12-24 17:43:12 +0400428 def supportedManagementProviders = ['os', 'aws', 'vsphere', 'equinix', 'equinixmetalv2', 'azure']
429 def supportedRegionalProviders = ['os', 'vsphere', 'equinix', 'equinixmetalv2', 'bm', 'azure', 'aws']
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200430
431 def clusterTypes = ''
Владислав Наумов38ed7bf2020-09-11 14:43:39 +0200432 if (keyword.toString().contains('multiregion')) {
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200433 common.infoMsg('Multiregion definition configured via gerrit keyword trigger')
434 clusterTypes = keyword[0][0].split('multiregion')[1].replaceAll('[\\[\\]]', '').trim().split(',')
435 } else {
436 common.infoMsg('Multiregion definition configured via environment variable')
437 clusterTypes = keyword.trim().split(',')
438 }
439
440 if (clusterTypes.size() != 2) {
Владислав Наумов482fb502020-10-30 17:59:27 +0100441 error("Incorrect regions definiton, valid scheme: [multiregion ${management}, ${region}], got: ${clusterTypes}")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200442 }
443
Владислав Наумовf793fe32020-09-11 15:19:19 +0200444 def desiredManagementProvider = clusterTypes[0].trim()
445 def desiredRegionalProvider = clusterTypes[1].trim()
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200446 if (! supportedManagementProviders.contains(desiredManagementProvider) || ! supportedRegionalProviders.contains(desiredRegionalProvider)) {
447 error("""unsupported management <-> regional bundle, available options:
Владислав Наумовf793fe32020-09-11 15:19:19 +0200448 management providers list - ${supportedManagementProviders}
449 regional providers list - ${supportedRegionalProviders}""")
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200450 }
451
452 return [
453 enabled: true,
454 managementLocation: desiredManagementProvider,
455 regionLocation: desiredRegionalProvider,
456 ]
vnaumov33747e12020-05-04 17:35:20 +0200457}
458
459/**
460 * Determine if custom si tests/pipelines refspec forwarded from gerrit change request
461
Владислав Наумов81777472021-03-09 15:14:27 +0400462 * Keyword list: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md
vnaumov33747e12020-05-04 17:35:20 +0200463 * Used for components team to test component changes w/ custom SI refspecs using kaas/core deployment jobs
464 * Example scheme:
465 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
466 * manage refspecs through Jenkins Job Parameters
467 *
azvyagintseva12230a2020-06-05 13:24:06 +0300468 * @return (map)[* siTests: (string) final refspec for si-tests
vnaumov33747e12020-05-04 17:35:20 +0200469 * siPipelines: (string) final refspec for si-pipelines
470 * ]
471 */
472def checkCustomSIRefspec() {
vnaumovbdb90222020-05-04 18:25:50 +0200473 def common = new com.mirantis.mk.Common()
474
vnaumov33747e12020-05-04 17:35:20 +0200475 // Available triggers and its sane defaults
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200476 def siTestsRefspec = env.SI_TESTS_REFSPEC ?: 'master'
477 def siPipelinesRefspec = env.SI_PIPELINES_REFSPEC ?: 'master'
Владислав Наумов2db15e22020-07-14 12:29:22 +0200478 def siTestsDockerImage = env.SI_TESTS_DOCKER_IMAGE ?: 'docker-dev-kaas-local.docker.mirantis.net/mirantis/kaas/si-test'
479 def siTestsDockerImageTag = env.SI_TESTS_DOCKER_IMAGE_TAG ?: 'master'
Владислав Наумов6c2afff2020-06-05 12:54:53 +0200480 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
vnaumov33747e12020-05-04 17:35:20 +0200481
482 def siTestMatches = (commitMsg =~ /(\[si-tests-ref\s*refs\/changes\/.*?\])/)
483 def siPipelinesMatches = (commitMsg =~ /(\[si-pipelines-ref\s*refs\/changes\/.*?\])/)
484
485 if (siTestMatches.size() > 0) {
486 siTestsRefspec = siTestMatches[0][0].split('si-tests-ref')[1].replaceAll('[\\[\\]]', '').trim()
Владислав Наумов7f6c0882021-03-23 19:10:57 +0400487 siTestsDockerImage = "docker-review-local.docker.mirantis.net/review/kaas-si-test-${siTestsRefspec.split('/')[-2]}"
Владислав Наумов2db15e22020-07-14 12:29:22 +0200488 siTestsDockerImageTag = siTestsRefspec.split('/')[-1]
vnaumov33747e12020-05-04 17:35:20 +0200489 }
490 if (siPipelinesMatches.size() > 0) {
491 siPipelinesRefspec = siPipelinesMatches[0][0].split('si-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
492 }
493
494 common.infoMsg("""
495 kaas/si-pipelines will be fetched from: ${siPipelinesRefspec}
496 kaas/si-tests will be fetched from: ${siTestsRefspec}
Владислав Наумов2db15e22020-07-14 12:29:22 +0200497 kaas/si-tests as dockerImage will be fetched from: ${siTestsDockerImage}:${siTestsDockerImageTag}
Владислав Наумов81777472021-03-09 15:14:27 +0400498 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов2db15e22020-07-14 12:29:22 +0200499 return [siTests: siTestsRefspec, siPipelines: siPipelinesRefspec, siTestsDockerImage: siTestsDockerImage, siTestsDockerImageTag: siTestsDockerImageTag]
vnaumov33747e12020-05-04 17:35:20 +0200500}
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200501
Владислав Наумов9080f372020-06-08 13:57:16 +0200502/**
Владислав Наумов418042b2020-07-09 18:31:10 +0200503 * Parse additional configuration for kaas component CICD repo
Владислав Наумов30a516c2020-07-09 13:15:41 +0200504 * @param configurationFile (str) path to configuration file in yaml format
505 *
506 * @return (map)[ siTestsFeatureFlags (string) dedicated feature flags that will be used in SI tests,
507 * ]
508 */
509def parseKaaSComponentCIParameters(configurationFile){
510 def common = new com.mirantis.mk.Common()
511 def ciConfig = readYaml file: configurationFile
512 def ciSpec = [
513 siTestsFeatureFlags: env.SI_TESTS_FEATURE_FLAGS ?: '',
514 ]
515
516 if (ciConfig.containsKey('si-tests-feature-flags')) {
517 common.infoMsg("""SI tests feature flags customization detected,
518 results will be merged with existing flags: [${ciSpec['siTestsFeatureFlags']}] identification...""")
519
520 def ffMeta = ciSpec['siTestsFeatureFlags'].tokenize(',').collect { it.trim() }
521 ffMeta.addAll(ciConfig['si-tests-feature-flags'])
Владислав Наумов30a516c2020-07-09 13:15:41 +0200522
Владислав Наумовcb5ffca2020-07-14 15:28:36 +0200523 ciSpec['siTestsFeatureFlags'] = ffMeta.unique().join(',')
Владислав Наумов30a516c2020-07-09 13:15:41 +0200524 common.infoMsg("SI tests custom feature flags: ${ciSpec['siTestsFeatureFlags']}")
525 }
526
527 common.infoMsg("""Additional ci configuration parsed successfully:
528 siTestsFeatureFlags: ${ciSpec['siTestsFeatureFlags']}""")
529 return ciSpec
530}
531
532/**
533 * Determine if custom kaas core/pipelines refspec forwarded from gerrit change request
Владислав Наумов9080f372020-06-08 13:57:16 +0200534
Владислав Наумов81777472021-03-09 15:14:27 +0400535 * Keyword list: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md
Владислав Наумов9080f372020-06-08 13:57:16 +0200536 * Used for components team to test component changes w/ custom Core refspecs using kaas/core deployment jobs
537 * Example scheme:
538 * New CR pushed in kubernetes/lcm-ansible -> parsing it's commit body and get custom test refspecs -> trigger deployment jobs from kaas/core
539 * manage refspecs through Jenkins Job Parameters
540 *
541 * @return (map)[ core: (string) final refspec for kaas/core
542 * corePipelines: (string) final refspec for pipelines in kaas/core
543 * ]
544 */
545def checkCustomCoreRefspec() {
546 def common = new com.mirantis.mk.Common()
547
548 // Available triggers and its sane defaults
549 def coreRefspec = env.KAAS_CORE_REFSPEC ?: 'master'
550 // by default using value of GERRIT_REFSPEC parameter in *kaas/core jobs*
551 def corePipelinesRefspec = env.KAAS_PIPELINE_REFSPEC ?: '\$GERRIT_REFSPEC'
552 def commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
553
554 def coreMatches = (commitMsg =~ /(\[core-ref\s*refs\/changes\/.*?\])/)
555 def corePipelinesMatches = (commitMsg =~ /(\[core-pipelines-ref\s*refs\/changes\/.*?\])/)
556
557 if (coreMatches.size() > 0) {
558 coreRefspec = coreMatches[0][0].split('core-ref')[1].replaceAll('[\\[\\]]', '').trim()
559 }
560 if (corePipelinesMatches.size() > 0) {
561 corePipelinesRefspec = corePipelinesMatches[0][0].split('core-pipelines-ref')[1].replaceAll('[\\[\\]]', '').trim()
562 }
563
564 common.infoMsg("""
565 kaas/core will be fetched from: ${coreRefspec}
566 kaas/core pipelines will be fetched from: ${corePipelinesRefspec}
Владислав Наумов81777472021-03-09 15:14:27 +0400567 Keywords: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md""")
Владислав Наумов9080f372020-06-08 13:57:16 +0200568 return [core: coreRefspec, corePipelines: corePipelinesRefspec]
569}
570
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200571
572/**
Владислав Наумов92288d92020-07-13 18:36:21 +0200573 * generate Jenkins Parameter objects from from text parameter with additonal kaas core context
574 * needed to forward inside kaas core set of jobs
575 *
576 * @param context (string) Representation of the string enviroment variables needed for kaas core jobs in yaml format
577 * @return (list)[ string(name: '', value: ''),
578 * ]
579 */
580def generateKaaSVarsFromContext(context) {
581 def common = new com.mirantis.mk.Common()
582 def parameters = []
583 def config = readYaml text: context
584
585 config.each { k,v ->
586 common.infoMsg("Custom KaaS Core context parameter: ${k}=${v}")
587 parameters.add(string(name: k, value: v))
588 }
589
590 return parameters
591}
592
593/**
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200594 * Trigger KaaS demo jobs based on AWS/OS providers with customized test suite, parsed from external sources (gerrit commit/jj vars)
Владислав Наумов81777472021-03-09 15:14:27 +0400595 * Keyword list: https://gerrit.mcp.mirantis.com/plugins/gitiles/kaas/core/+/refs/heads/master/hack/ci-gerrit-keywords.md
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200596 * Used for components team to test component changes w/ customized SI tests/refspecs using kaas/core deployment jobs
597 *
Владислав Наумов418042b2020-07-09 18:31:10 +0200598 * @param: component (string) component name [iam, lcm, stacklight]
599 * @param: patchSpec (string) Patch for kaas/cluster releases in json format
600 * @param: configurationFile (string) Additional file for component repo CI config in yaml format
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200601 */
Владислав Наумов92288d92020-07-13 18:36:21 +0200602def triggerPatchedComponentDemo(component, patchSpec = '', configurationFile = '.ci-parameters.yaml', coreContext = '') {
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200603 def common = new com.mirantis.mk.Common()
604 // Determine if custom trigger keywords forwarded from gerrit
605 def triggers = checkDeploymentTestSuite()
606 // Determine SI refspecs
607 def siRefspec = checkCustomSIRefspec()
Владислав Наумов9080f372020-06-08 13:57:16 +0200608 // Determine Core refspecs
609 def coreRefspec = checkCustomCoreRefspec()
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200610
Владислав Наумов418042b2020-07-09 18:31:10 +0200611 // Determine component repo ci configuration
612 def ciSpec = [:]
613 def componentFeatureFlags = env.SI_TESTS_FEATURE_FLAGS ?: ''
614 if (fileExists(configurationFile)) {
615 common.infoMsg('Component CI configuration file detected, parsing...')
616 ciSpec = parseKaaSComponentCIParameters(configurationFile)
617 componentFeatureFlags = ciSpec['siTestsFeatureFlags']
618 } else {
619 common.warningMsg('''Component CI configuration file is not exists,
Владислав Наумовc17dd552020-07-29 17:07:38 +0200620 several code-management features may be unavailable,
Владислав Наумов92288d92020-07-13 18:36:21 +0200621 follow https://mirantis.jira.com/wiki/spaces/QA/pages/2310832276/SI-tests+feature+flags#%5BUpdated%5D-Using-a-feature-flag
622 to create the configuration file''')
Владислав Наумов418042b2020-07-09 18:31:10 +0200623 }
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400624
625 def platforms = []
626 if (component == 'ipam' && triggers.vsphereDemoEnabled) {
627 // Currently only vsphere demo is required for IPAM component
628 platforms.add('vsphere')
629 } else {
630 if (triggers.osDemoEnabled) {
631 platforms.add('openstack')
632 }
633 if (triggers.awsOnDemandDemoEnabled) {
634 platforms.add('aws')
635 }
636 if (triggers.equinixOnDemandDemoEnabled) {
637 platforms.add('equinix')
638 }
Владислав Наумов144956f2021-10-14 17:49:19 +0200639 if (triggers.equinixMetalV2OnDemandDemoEnabled) {
640 platforms.add('equinixmetalv2')
641 }
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200642 if (triggers.azureOnDemandDemoEnabled) {
643 platforms.add('azure')
644 }
Ivan Berezovskiyb0229d02021-05-17 16:55:18 +0400645 if (triggers.vsphereDemoEnabled) {
646 platforms.add('vsphere')
647 }
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400648 }
649
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200650 def jobs = [:]
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200651 def parameters = [
Владислав Наумов9080f372020-06-08 13:57:16 +0200652 string(name: 'GERRIT_REFSPEC', value: coreRefspec.core),
653 string(name: 'KAAS_PIPELINE_REFSPEC', value: coreRefspec.corePipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200654 string(name: 'SI_TESTS_REFSPEC', value: siRefspec.siTests),
Владислав Наумов418042b2020-07-09 18:31:10 +0200655 string(name: 'SI_TESTS_FEATURE_FLAGS', value: componentFeatureFlags),
Владислав Наумов2db15e22020-07-14 12:29:22 +0200656 string(name: 'SI_TESTS_DOCKER_IMAGE', value: siRefspec.siTestsDockerImage),
657 string(name: 'SI_TESTS_DOCKER_IMAGE_TAG', value: siRefspec.siTestsDockerImageTag),
Владислав Наумов4a5c3242020-06-08 14:36:11 +0200658 string(name: 'SI_PIPELINES_REFSPEC', value: siRefspec.siPipelines),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200659 string(name: 'CUSTOM_RELEASE_PATCH_SPEC', value: patchSpec),
Mikhail Ivanov74504372021-05-21 17:01:06 +0400660 string(name: 'KAAS_CHILD_CLUSTER_RELEASE_NAME', value: triggers.childDeployCustomRelease),
Mikhail Ivanovb6283f72021-11-24 18:34:57 +0400661 string(name: 'OPENSTACK_CLOUD_LOCATION', value: triggers.osCloudLocation),
Владислав Наумовb8305e22021-02-10 17:23:12 +0100662 booleanParam(name: 'OFFLINE_MGMT_CLUSTER', value: triggers.proxyConfig['mgmtOffline']),
Владислав Наумовf8f23fa2021-04-01 16:57:52 +0200663 booleanParam(name: 'OFFLINE_CHILD_CLUSTER', value: triggers.proxyConfig['childOffline']),
Владислав Наумов257ea132021-04-14 14:44:13 +0200664 booleanParam(name: 'PROXY_CHILD_CLUSTER', value: triggers.proxyConfig['childProxy']),
Владислав Наумов44c64b72020-12-04 20:22:53 +0100665 booleanParam(name: 'SEED_MACOS', value: triggers.useMacOsSeedNode),
Владислав Наумов080d9412020-07-29 13:05:14 +0200666 booleanParam(name: 'UPGRADE_MGMT_CLUSTER', value: triggers.upgradeMgmtEnabled),
Victor Ryzhenkind2b7b662021-08-23 14:18:38 +0400667 booleanParam(name: 'ENABLE_LMA_LOGGING', value: triggers.enableLMALoggingEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200668 booleanParam(name: 'RUN_UI_E2E', value: triggers.runUie2eEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200669 booleanParam(name: 'RUN_MGMT_CFM', value: triggers.runMgmtConformanceEnabled),
slalov13e579c2022-01-31 21:37:02 +0400670 booleanParam(name: 'RUN_MAINTENANCE_TEST', value: triggers.runMaintenanceTestEnable),
Владислав Наумов9cec55d2021-08-03 15:00:59 +0200671 booleanParam(name: 'RUN_LMA_TEST', value: triggers.runLMATestEnabled),
Vladyslav Drokc4f9c1b2021-07-22 15:34:24 +0200672 booleanParam(name: 'RUN_MGMT_USER_CONTROLLER_TEST', value: triggers.runMgmtUserControllerTestEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200673 booleanParam(name: 'DEPLOY_CHILD_CLUSTER', value: triggers.deployChildEnabled),
674 booleanParam(name: 'UPGRADE_CHILD_CLUSTER', value: triggers.upgradeChildEnabled),
slalov574123e2022-04-06 17:24:19 +0400675 booleanParam(name: 'RUN_PROXY_CHILD_TEST', value: triggers.runProxyChildTestEnabled),
Владислав Наумов0dc99252020-11-13 13:30:48 +0100676 booleanParam(name: 'ATTACH_BYO', value: triggers.attachBYOEnabled),
Владислав Наумовcdbd84e2020-12-01 16:51:09 +0100677 booleanParam(name: 'UPGRADE_BYO', value: triggers.upgradeBYOEnabled),
Vladislav Naumov7930ab22021-11-22 18:24:24 +0100678 booleanParam(name: 'RUN_BYO_MATRIX', value: triggers.runBYOMatrixEnabled),
Владислав Наумов080d9412020-07-29 13:05:14 +0200679 booleanParam(name: 'RUN_CHILD_CFM', value: triggers.runChildConformanceEnabled),
Ivan Berezovskiycbf9eeb2021-03-22 15:57:32 +0400680 booleanParam(name: 'ALLOW_AWS_ON_DEMAND', value: triggers.awsOnDemandDemoEnabled),
Владислав Наумовe021b022021-05-06 11:26:38 +0200681 booleanParam(name: 'ALLOW_EQUINIX_ON_DEMAND', value: triggers.equinixOnDemandDemoEnabled),
Владислав Наумов82305e92021-10-14 20:45:20 +0200682 booleanParam(name: 'ALLOW_EQUINIXMETALV2_ON_DEMAND', value: triggers.equinixMetalV2OnDemandDemoEnabled),
Vladislav Naumov42b71dc2021-11-22 13:09:42 +0100683 booleanParam(name: 'EQUINIXMETALV2_CHILD_DIFF_METRO', value: triggers.equinixMetalV2ChildDiffMetroEnabled),
eromanovad3397512021-04-01 20:19:19 +0400684 booleanParam(name: 'EQUINIX_ON_AWS_DEMO', value: triggers.equinixOnAwsDemoEnabled),
Владислав Наумовc52dd9d2021-06-28 16:27:29 +0200685 booleanParam(name: 'ALLOW_AZURE_ON_DEMAND', value: triggers.azureOnDemandDemoEnabled),
Владислав Наумов2d3db332021-06-15 15:19:19 +0200686 booleanParam(name: 'AZURE_ON_AWS_DEMO', value: triggers.azureOnAwsDemoEnabled),
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200687 ]
Владислав Наумов92288d92020-07-13 18:36:21 +0200688
Владислав Наумов765f3bd2020-09-07 18:09:24 +0200689 // customize multiregional demo
690 if (triggers.multiregionalConfiguration.enabled) {
691 parameters.add(string(name: 'MULTIREGION_SETUP',
692 value: "${triggers.multiregionalConfiguration.managementLocation},${triggers.multiregionalConfiguration.regionLocation}"
693 ))
694 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200695
Владислав Наумов92288d92020-07-13 18:36:21 +0200696 // Determine component team custom context
697 if (coreContext != '') {
698 common.infoMsg('Additional KaaS Core context detected, will be forwarded into kaas core cicd...')
699 def additionalParameters = generateKaaSVarsFromContext(coreContext)
Владислав Наумовbef51a92020-10-01 17:36:51 +0200700 parameters.addAll(additionalParameters)
Владислав Наумов92288d92020-07-13 18:36:21 +0200701 }
702
Владислав Наумовaa430612020-06-08 17:18:31 +0200703 def jobResults = []
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400704
705 platforms.each { platform ->
706 jobs["kaas-core-${platform}-patched-${component}"] = {
Vladislav Naumov5313a202021-04-07 17:13:39 +0000707 try {
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400708 common.infoMsg("Deploy: patched KaaS demo with ${platform} provider")
709 def job_info = build job: "kaas-testing-core-${platform}-workflow-${component}", parameters: parameters, wait: true
710 def build_description = job_info.getDescription()
711 def build_result = job_info.getResult()
Vladislav Naumov5313a202021-04-07 17:13:39 +0000712 jobResults.add(build_result)
Владислав Наумовd044e842020-06-17 15:33:43 +0200713
Vladislav Naumov5313a202021-04-07 17:13:39 +0000714 if (build_description) {
715 currentBuild.description += build_description
716 }
717 } finally {
Ivan Berezovskiy91ede502021-05-13 21:05:36 +0400718 common.infoMsg("Patched KaaS demo with ${platform} provider finished")
Vladislav Naumov5313a202021-04-07 17:13:39 +0000719 }
720 }
721 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200722
723 common.infoMsg('Trigger KaaS demo deployments according to defined provider set')
Владислав Наумов37f7f842021-03-09 16:08:39 +0400724 if (jobs.size() == 0) {
725 error('No demo jobs matched with keywords, execution will be aborted, at least 1 provider should be enabled')
726 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200727 // Limit build concurency workaround examples: https://issues.jenkins-ci.org/browse/JENKINS-44085
728 parallel jobs
Владислав Наумовaa430612020-06-08 17:18:31 +0200729
730 if (jobResults.contains('FAILURE')) {
Владислав Наумовf86b1112020-06-09 14:04:48 +0200731 common.infoMsg('One of parallel downstream jobs is failed, mark executor job as failed')
Владислав Наумовaa430612020-06-08 17:18:31 +0200732 currentBuild.result = 'FAILURE'
733 }
Владислав Наумов2a982ff2020-06-02 19:06:46 +0200734}
Владислав Наумов30a516c2020-07-09 13:15:41 +0200735
736
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400737/**
738 * Function currently supported to be called from aws or vsphere demos. It gets particular demo context
Владислав Наумов33e1e812021-08-17 17:09:25 +0200739 * and generate proper lockResources data and netMap data for vsphere,equinix related clusters.
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400740 *
741 * @param: callBackDemo (string) Demo which requested to generate lockResources [aws or vsphere]
742 * @param: triggers (map) Custom trigger keywords forwarded from gerrit
743 * @param: multiregionalConfiguration (map) Multiregional configuration
744 * @return (map) Return aggregated map with lockResources and netMap
745 */
746
747
748def generateLockResources(callBackDemo, triggers) {
749 def common = new com.mirantis.mk.Common()
Владислав Наумов33e1e812021-08-17 17:09:25 +0200750 def netMap = [
751 vsphere: [:],
752 equinix: [:],
753 ]
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400754 // Define vsphere locklabels with initial quantity
755 def lockLabels = [
756 vsphere_networking_core_ci: 0,
757 vsphere_offline_networking_core_ci: 0,
758 ]
759 def deployChild = triggers.deployChildEnabled
760 def multiregionConfig = triggers.multiregionalConfiguration
761 def runMultiregion = multiregionConfig.enabled
762
763 // Generate vsphere netMap and lockLabels based on demo context
764 switch (callBackDemo) {
765 case 'aws':
766 // Add aws specific lock label with quantity calculated based on single mgmt deploy or mgmt + child
767 lockLabels['aws_core_ci_queue'] = triggers.demoWeight
Sergey Kolekonovf4c1f492022-02-03 14:44:45 +0400768 if (triggers.runBYOMatrixEnabled) { lockLabels['aws_core_ci_queue'] += 6 }
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400769
770 // Define netMap for Vsphere region
Владислав Наумовf60480d2021-10-15 14:04:01 +0200771 if (runMultiregion && multiregionConfig.managementLocation == 'aws' &&
772 multiregionConfig.regionLocation == 'vsphere') {
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400773 if (deployChild) {
Владислав Наумов33e1e812021-08-17 17:09:25 +0200774 addToProviderNetMap(netMap, 'vsphere', 'regional-child')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400775 }
Владислав Наумов33e1e812021-08-17 17:09:25 +0200776 addToProviderNetMap(netMap, 'vsphere', 'region')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400777 }
778 break
779 case 'vsphere':
Владислав Наумов33e1e812021-08-17 17:09:25 +0200780 addToProviderNetMap(netMap, 'vsphere', 'mgmt')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400781 if (deployChild) {
Владислав Наумов33e1e812021-08-17 17:09:25 +0200782 addToProviderNetMap(netMap, 'vsphere', 'child')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400783 }
784 if (runMultiregion && multiregionConfig.managementLocation == 'vsphere' &&
785 multiregionConfig.regionLocation == 'vsphere') {
786 if (deployChild) {
Владислав Наумов33e1e812021-08-17 17:09:25 +0200787 addToProviderNetMap(netMap, 'vsphere', 'regional-child')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400788 }
Владислав Наумов33e1e812021-08-17 17:09:25 +0200789 addToProviderNetMap(netMap, 'vsphere', 'region')
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400790 }
791 break
792 default:
793 error('Supposed to be called from aws or vsphere demos only')
794 }
795
796 // Checking gerrit triggers and manage lock label quantity and network types in case of Offline deployment
797 // Vsphere labels only
Владислав Наумов33e1e812021-08-17 17:09:25 +0200798 netMap['vsphere'].each { clusterType, netConfig ->
799 if (triggers.proxyConfig["${clusterType}Offline"] == true ||
800 (clusterType == 'regional-child' && triggers.proxyConfig['childOffline'] == true) ||
801 (clusterType == 'region' && triggers.proxyConfig['mgmtOffline'])) {
802
803 netMap['vsphere'][clusterType]['netName'] = 'offline'
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400804 lockLabels['vsphere_offline_networking_core_ci']++
805 } else {
806 lockLabels['vsphere_networking_core_ci']++
807 }
808 }
809
810 // generate lock metadata
811 def lockResources = []
812 lockLabels.each { label, quantity ->
813 if (quantity > 0) {
814 def res = [
815 label: label,
816 quantity: quantity,
817 ]
818 lockResources.add(res)
819 }
820 }
821
822 common.infoMsg("""Generated vsphere netMap: ${netMap}
823 Generated lockResources: ${lockResources}""")
824
825 return [
826 netMap: netMap,
827 lockResources: lockResources,
828 ]
829}
830
831/**
832 * Function gets vsphere netMap or empty map and adds new vsphere clusterType with default netName
833 * and empty rangeConfig to the this map.
834 *
Владислав Наумов33e1e812021-08-17 17:09:25 +0200835 * @param: netMap (string) vsphere, equinix netMap or empty map
836 * @param: provider (string) provider type
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400837 * @param: clusterType (string) Vsphere cluster type
838 */
839
Владислав Наумов33e1e812021-08-17 17:09:25 +0200840def addToProviderNetMap (netMap, provider, clusterType) {
841 switch (provider) {
842 case 'equinix':
843 netMap[provider][clusterType] = [
844 vlanConfig: '',
845 ]
846 break
847 case 'vsphere':
848 netMap[provider][clusterType] = [
849 netName: 'default',
850 rangeConfig: '',
851 ]
852 break
853 default:
854 error('Net map locks supported for Equinix/Vsphere providers only')
855 }
Stanislav Riazanov78fa7df2021-05-28 20:28:59 +0400856}
Dmitry Teselkinfce71aa2022-03-05 19:36:52 +0300857
858/**
859* getCIKeywordsFromCommitMsg parses commit message and returns all gerrit keywords with their values as a list of maps.
860* Each element (map) contains keys 'key' for keyword name and 'value' for its value.
861* If keyword contains only 'key' part then 'value' is boolean True.
862* This function does not perform keywords validation.
863* First line of a commit message is ignored.
864* To use '[' or ']' characters inside keyword prepend it with backslash '\'.
865* TODO: Remove backslash chars from values if they prepend '[' or ']'.
866**/
867
868List getCIKeywordsFromCommitMsg() {
869 String commitMsg = env.GERRIT_CHANGE_COMMIT_MESSAGE ? new String(env.GERRIT_CHANGE_COMMIT_MESSAGE.decodeBase64()) : ''
870 List commitMsgLines = commitMsg.split('\n')
871 List keywords = []
872 if (commitMsgLines.size() < 2) {
873 return keywords
874 }
875
876 String commitMsgBody = commitMsgLines[1..-1].join('\n')
877
878 // Split commit message body to chunks using '[' or ']' as delimiter,
879 // ignoring them if prepended by backslash (regex negative lookbehind).
880 // Resulting list will have chunks between '[' and ']' at odd indexes.
881 List parts = commitMsgBody.split(/(?<!\\)[\[\]]/)
882
883 // Iterate chunks by odd indexes only, trim values and split to
884 // <key> / <value> pair where <key> is the part of a sting before the first
885 // whitespace delimiter, and <value> is the rest (may include whitespaces).
886 // If there is no whitespace in the string then this is a 'switch'
887 // and <value> will be boolean True.
888 for (i = 1; i < parts.size(); i += 2) {
889 def (key, value) = (parts[i].trim().split(/\s+/, 2) + [true, ])[0..1]
890 keywords.add(['key': key, 'value': value])
891 }
892
893 return keywords
894}
895
896/**
897* getJobsParamsFromCommitMsg parses list of CI keywords and returns values of 'job-params' keyword
898* that were specified for given job name. `job-params` keyword has the following structure
899*
900* [job-params <job name> <parameter name> <parameter value>]
901*
902* Return value is a Map that contains those parameters using the following structure:
903*
904* <job name>:
905* <parameter name>: <parameter value>
906*
907**/
908Map getJobsParamsFromCommitMsg() {
909 List keywords = getCIKeywordsFromCommitMsg()
910
911 List jobsParamsList = []
912 keywords.findAll{ it.key == 'job-params' }.collect(jobsParamsList) {
913 def (name, params) = (it['value'].split(/\s+/, 2) + [null, ])[0..1]
914 def (key, value) = params.split(/\s+/, 2)
915 ['name': name, 'key': key, 'value': value]
916 }
917
918 Map jobsParams = jobsParamsList.inject([:]) { result, it ->
919 if (!result.containsKey(it.name)) {
920 result[it.name] = [:]
921 }
922 result[it.name][it.key] = it.value
923 result
924 }
925
926 return jobsParams
927}
928
929
930/**
931* getJobParamsFromCommitMsg returns key:value Map of parameters set for a job in commit message.
932* It uses getJobsParamsFromCommitMsg to get all parameters from commit message and then
933* uses only those parametes that were set to all jobs (with <job name> == '*') or to
934* a particular job. Parameters set to a particular job have higher precedence.
935*
936* Return value is a Map that contains those parameters:
937*
938* <parameter name>: <parameter value>
939*
940**/
941Map getJobParamsFromCommitMsg(String jobName) {
942 jobsParams = getJobsParamsFromCommitMsg()
943 jobParams = jobsParams.getOrDefault('*', [:])
944 if (jobName) {
945 jobParams.putAll(jobsParams.getOrDefault(jobName, [:]))
946 }
947 return jobParams
948}