blob: 26b64b39f40cd7463130f4bfb0b570ceba927682 [file] [log] [blame]
Lionel Jouinc4037892022-11-16 15:53:04 +01001/*
2Copyright (c) 2022 Nordix Foundation
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
Lionel Jouinc0ae7182022-10-24 17:28:37 +020016import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
17
Lionel Jouin1317f9e2022-11-17 11:20:32 +010018node('nordix-nsm-build-ubuntu2204') {
Lionel Jouinc0ae7182022-10-24 17:28:37 +020019 build_number = env.BUILD_NUMBER
20 workspace = env.WORKSPACE
21 ws("${workspace}/${build_number}") {
22 def git_project = params.GIT_PROJECT
23 def current_branch = params.CURRENT_BRANCH
24 def default_branch = params.DEFAULT_BRANCH
25 def next = params.NEXT
26
27 def meridio_version = params.MERIDIO_VERSION
28 def tapa_version = params.TAPA_VERSION
29 def kubernetes_version = params.KUBERNETES_VERSION
30 def nsm_version = params.NSM_VERSION
31 def ip_family = params.IP_FAMILY
Lionel Jouin848fab12022-10-31 17:32:58 +010032 def number_of_workers = params.NUMBER_OF_WORKERS
33 def environment_name = params.ENVIRONMENT_NAME
Lionel Jouinc4037892022-11-16 15:53:04 +010034 def focus = params.FOCUS
35 def skip = params.SKIP
Lionel Jouin482e6fb2024-02-16 18:09:03 +010036 def kind_external_host_default_route = params.KIND_EXTERNAL_HOST_DEFAULT_ROUTE
Lionel Jouin848fab12022-10-31 17:32:58 +010037
38 def seed = params.SEED
Lionel Jouinc0ae7182022-10-24 17:28:37 +020039
40 stage('Clone/Checkout') {
41 git branch: default_branch, url: git_project
42 checkout([
43 $class: 'GitSCM',
44 branches: [[name: current_branch]],
45 extensions: [],
46 userRemoteConfigs: [[
47 refspec: '+refs/pull/*/head:refs/remotes/origin/pr/*',
48 url: git_project
49 ]]
50 ])
51 sh 'git show'
52 }
Lionel Jouin1e04de62022-11-18 11:59:18 +010053 timeout(120) {
Lionel Jouinc0ae7182022-10-24 17:28:37 +020054 stage('Environment') {
Lionel Jouin848fab12022-10-31 17:32:58 +010055 currentBuild.description = "Meridio version: $meridio_version / TAPA version: $tapa_version / NSM version: $nsm_version / IP Family: $ip_family / Kubernetes version: $kubernetes_version / Current Branch: $current_branch / Seed: $seed"
Lionel Jouinc0ae7182022-10-24 17:28:37 +020056
Lionel Jouin482e6fb2024-02-16 18:09:03 +010057 def command = "make -s -C test/e2e/environment/$environment_name/ KUBERNETES_VERSION=$kubernetes_version NSM_VERSION=$nsm_version IP_FAMILY=$ip_family KUBERNETES_WORKERS=$number_of_workers MERIDIO_VERSION=$meridio_version TAPA_VERSION=$tapa_version KIND_EXTERNAL_HOST_DEFAULT_ROUTE=$kind_external_host_default_route"
Lionel Jouinf26ac952022-10-25 18:38:18 +020058 try {
Lionel Jouinc4037892022-11-16 15:53:04 +010059 ExecSh(command).call()
Lionel Jouind3f88422022-11-21 10:33:47 +010060 } catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
61 currentBuild.result = 'ABORTED'
Lionel Jouinf26ac952022-10-25 18:38:18 +020062 } catch (Exception e) {
Lionel Jouin848fab12022-10-31 17:32:58 +010063 unstable 'Environment setup failed'
64 currentBuild.result = 'FAILURE'
Lionel Jouinf26ac952022-10-25 18:38:18 +020065 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +020066 }
67 stage('E2E') {
Lionel Jouind3f88422022-11-21 10:33:47 +010068 if (currentBuild.result != 'FAILURE' && currentBuild.result != 'ABORTED') {
Lionel Jouinc4037892022-11-16 15:53:04 +010069 def command = "make e2e E2E_PARAMETERS=\"\$(cat ./test/e2e/environment/$environment_name/$ip_family/config.txt | tr '\\n' ' ')\" E2E_SEED=$seed E2E_FOCUS=\"$focus\" E2E_SKIP=\"$skip\""
Lionel Jouin848fab12022-10-31 17:32:58 +010070 try {
Lionel Jouinc4037892022-11-16 15:53:04 +010071 ExecSh(command).call()
72 currentBuild.result = 'SUCCESS'
Lionel Jouind3f88422022-11-21 10:33:47 +010073 } catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
74 currentBuild.result = 'ABORTED'
Lionel Jouin848fab12022-10-31 17:32:58 +010075 } catch (Exception e) {
76 unstable 'E2E Tests failed'
77 currentBuild.result = 'FAILURE'
78 }
79 } else {
80 Utils.markStageSkippedForConditional('E2E')
Lionel Jouinf26ac952022-10-25 18:38:18 +020081 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +020082 }
83 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +020084 stage('Report') {
Lionel Jouin848fab12022-10-31 17:32:58 +010085 try {
Lionel Jouin0c44c682023-02-16 18:14:07 +010086 Report(build_number).call()
Lionel Jouind3f88422022-11-21 10:33:47 +010087 } catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
88 currentBuild.result = 'ABORTED'
Lionel Jouin848fab12022-10-31 17:32:58 +010089 } catch (Exception e) {
90 unstable 'Failed to create the report'
91 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +020092 }
93 stage('Next') {
Lionel Jouinc4037892022-11-16 15:53:04 +010094 if (next == true && currentBuild.result != 'ABORTED') {
95 Next(next, number_of_workers, environment_name, focus, skip, current_branch).call()
96 } else {
97 Utils.markStageSkippedForConditional('Next')
98 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +020099 }
Lionel Jouinf77e9e22022-10-26 13:14:51 +0200100 stage('Cleanup') {
101 Cleanup()
102 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200103 }
104}
105
Lionel Jouinc4037892022-11-16 15:53:04 +0100106def Next(next, number_of_workers, environment_name, focus, skip, current_branch) {
107 return {
Lionel Jouind3f88422022-11-21 10:33:47 +0100108 def meridio_version = GetMeridioVersion(environment_name)
109 def tapa_version = GetTAPAVersion(environment_name)
110 def nsm_version = GetNSMVersion(environment_name)
111 def kubernetes_version = GetKubernetesVersion(environment_name)
112 def ip_family = GetIPFamily(environment_name)
Lionel Jouinc4037892022-11-16 15:53:04 +0100113 def seed = GetSeed()
114 echo "Meridio version: $meridio_version / TAPA version: $tapa_version / NSM version: $nsm_version / IP Family: $ip_family / Kubernetes version: $kubernetes_version / Seed: $seed"
115 build job: 'meridio-e2e-test-kind', parameters: [
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200116 string(name: 'NEXT', value: 'true'),
117 string(name: 'MERIDIO_VERSION', value: "$meridio_version"),
118 string(name: 'TAPA_VERSION', value: "$tapa_version"),
119 string(name: 'KUBERNETES_VERSION', value: "$kubernetes_version"),
120 string(name: 'NSM_VERSION', value: "$nsm_version"),
Lionel Jouin848fab12022-10-31 17:32:58 +0100121 string(name: 'IP_FAMILY', value: "$ip_family"),
122 string(name: 'NUMBER_OF_WORKERS', value: "$number_of_workers"),
123 string(name: 'ENVIRONMENT_NAME', value: "$environment_name"),
Lionel Jouinc4037892022-11-16 15:53:04 +0100124 string(name: 'SEED', value: "$seed"),
125 string(name: 'FOCUS', value: "$focus"),
126 string(name: 'SKIP', value: "$skip"),
127 string(name: 'CURRENT_BRANCH', value: "$current_branch"),
128 string(name: 'DRY_RUN', value: env.DRY_RUN)
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200129 ], wait: false
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200130 }
131}
132
Lionel Jouind3f88422022-11-21 10:33:47 +0100133def GetMeridioVersion(environment_name) {
134 def number_of_versions = sh(script: "cat test/e2e/environment/$environment_name/test-scope.yaml | yq '.Meridio[]' | wc -l", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200135 def index_of_version_temp = sh(script: "shuf -i 1-$number_of_versions -n1", returnStdout: true).trim()
136 def index_of_version = sh(script: "expr $index_of_version_temp - 1 || true", returnStdout: true).trim()
Lionel Jouind3f88422022-11-21 10:33:47 +0100137 return sh(script: "cat test/e2e/environment/$environment_name/test-scope.yaml | yq '.Meridio[$index_of_version]'", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200138}
139
Lionel Jouind3f88422022-11-21 10:33:47 +0100140def GetTAPAVersion(environment_name) {
141 def number_of_versions = sh(script: "cat test/e2e/environment/$environment_name/test-scope.yaml | yq '.TAPA[]' | wc -l", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200142 def index_of_version_temp = sh(script: "shuf -i 1-$number_of_versions -n1", returnStdout: true).trim()
143 def index_of_version = sh(script: "expr $index_of_version_temp - 1 || true", returnStdout: true).trim()
Lionel Jouind3f88422022-11-21 10:33:47 +0100144 return sh(script: "cat test/e2e/environment/$environment_name/test-scope.yaml | yq '.TAPA[$index_of_version]'", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200145}
146
Lionel Jouind3f88422022-11-21 10:33:47 +0100147def GetNSMVersion(environment_name) {
148 def number_of_versions = sh(script: "cat test/e2e/environment/$environment_name/test-scope.yaml | yq '.NSM[]' | wc -l", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200149 def index_of_version_temp = sh(script: "shuf -i 1-$number_of_versions -n1", returnStdout: true).trim()
150 def index_of_version = sh(script: "expr $index_of_version_temp - 1 || true", returnStdout: true).trim()
Lionel Jouind3f88422022-11-21 10:33:47 +0100151 return sh(script: "cat test/e2e/environment/$environment_name/test-scope.yaml | yq '.NSM[$index_of_version]'", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200152}
153
Lionel Jouind3f88422022-11-21 10:33:47 +0100154def GetKubernetesVersion(environment_name) {
155 def number_of_versions = sh(script: "cat test/e2e/environment/$environment_name/test-scope.yaml | yq '.Kubernetes[]' | wc -l", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200156 def index_of_version_temp = sh(script: "shuf -i 1-$number_of_versions -n1", returnStdout: true).trim()
157 def index_of_version = sh(script: "expr $index_of_version_temp - 1 || true", returnStdout: true).trim()
Lionel Jouind3f88422022-11-21 10:33:47 +0100158 return sh(script: "cat test/e2e/environment/$environment_name/test-scope.yaml | yq '.Kubernetes[$index_of_version]'", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200159}
160
Lionel Jouind3f88422022-11-21 10:33:47 +0100161def GetIPFamily(environment_name) {
162 def number_of_ip_family = sh(script: "cat test/e2e/environment/$environment_name/test-scope.yaml | yq '.IP-Family[]' | wc -l", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200163 def index_of_ip_family_temp = sh(script: "shuf -i 1-$number_of_ip_family -n1", returnStdout: true).trim()
164 def index_of_ip_family = sh(script: "expr $index_of_ip_family_temp - 1 || true", returnStdout: true).trim()
Lionel Jouind3f88422022-11-21 10:33:47 +0100165 return sh(script: "cat test/e2e/environment/$environment_name/test-scope.yaml | yq '.IP-Family[$index_of_ip_family]'", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200166}
167
Lionel Jouin848fab12022-10-31 17:32:58 +0100168def GetSeed() {
169 return sh(script: 'shuf -i 1-2147483647 -n1', returnStdout: true).trim()
170}
171
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200172// http://JENKINS_URL/job/meridio-e2e-test-kind/api/json?tree=allBuilds[status,timestamp,id,result,description]{0,9}&pretty=true
Lionel Jouin0c44c682023-02-16 18:14:07 +0100173def Report(id) {
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200174 return {
175 def jenkins_url = 'jenkins.nordix.org'
176
Lionel Jouinf26ac952022-10-25 18:38:18 +0200177 def success = ''
178 try {
179 success = sh(script: """
Lionel Jouinc4037892022-11-16 15:53:04 +0100180 data=\$(curl -s -L "http://$jenkins_url/job/meridio-e2e-test-kind/api/json?tree=allBuilds\\[status,timestamp,id,result,description\\]\\{0,1000\\}&pretty=true")
Lionel Jouinf26ac952022-10-25 18:38:18 +0200181 success=\$(echo \"\$data\" | jq -r '.allBuilds[] | select(.result == \"SUCCESS\") | [.description] | @tsv' | grep -v \"^\$\")
182 echo \$success
183 """, returnStdout: true).trim()
184 } catch (Exception e) {
185 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200186
Lionel Jouinf26ac952022-10-25 18:38:18 +0200187 def failure = ''
188 try {
189 failure = sh(script: """
Lionel Jouinc4037892022-11-16 15:53:04 +0100190 data=\$(curl -s -L "http://$jenkins_url/job/meridio-e2e-test-kind/api/json?tree=allBuilds\\[status,timestamp,id,result,description\\]\\{0,1000\\}&pretty=true")
Lionel Jouinf26ac952022-10-25 18:38:18 +0200191 failure=\$(echo \"\$data\" | jq -r '.allBuilds[] | select(.result == \"FAILURE\") | [.description] | @tsv' | grep -v \"^\$\")
192 echo \$failure
193 """, returnStdout: true).trim()
194 } catch (Exception e) {
195 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200196
197 ReportMeridio(success, failure).call()
198 ReportTAPA(success, failure).call()
199 ReportNSM(success, failure).call()
200 ReportIPFamily(success, failure).call()
201 ReportKubernetes(success, failure).call()
Lionel Jouinc4037892022-11-16 15:53:04 +0100202
Lionel Jouin0c44c682023-02-16 18:14:07 +0100203 sh 'printenv > _output/parameters.txt'
204 sh "echo 'RESULT=$currentBuild.result' >> _output/parameters.txt"
205
Lionel Jouinc4037892022-11-16 15:53:04 +0100206 try {
Lionel Jouin1e04de62022-11-18 11:59:18 +0100207 archiveArtifacts artifacts: '_output/**/*.*', followSymlinks: false
Lionel Jouin0c44c682023-02-16 18:14:07 +0100208 sh "tar -czvf ${id}.tar.gz -C _output ."
209 withCredentials([string(credentialsId: 'nsm-nordix-artifactory-api-key', variable: 'API_KEY')]) {
Lionel Jouin716e1ce2023-02-20 17:04:24 +0100210 sh "curl -H 'X-JFrog-Art-Api:${API_KEY}' -T ${id}.tar.gz 'https://artifactory.nordix.org/artifactory/cloud-native/meridio/e2e-test-reports/${id}.tar.gz'"
Lionel Jouin0c44c682023-02-16 18:14:07 +0100211 }
Lionel Jouinc4037892022-11-16 15:53:04 +0100212 } catch (Exception e) {
213 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200214 }
215}
216
217def ReportMeridio(success, failure) {
218 return {
219 def meridio_success = sh(script: "echo \"$success\" | grep -oP '(?<=Meridio version: ).*?(?=\\/)' | sort | uniq -c | awk '{ printf \"%s %s 0\\n\", \$2, \$1 }'", returnStdout: true).trim()
220 def meridio_failure = sh(script: "echo \"$failure\" | grep -oP '(?<=Meridio version: ).*?(?=\\/)' | sort | uniq -c | awk '{ printf \"%s 0 %s\\n\", \$2, \$1 }'", returnStdout: true).trim()
Lionel Jouinf26ac952022-10-25 18:38:18 +0200221 def meridio = sh(script: "echo \"$meridio_success\\n$meridio_failure\" | grep -v '^\$' | awk '{ success[\$1] += \$2 ; failure[\$1] += \$3 } END { for(elem in success) print elem, success[elem], failure[elem] }' | sort -k1", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200222 def formatted = sh(script: "echo \"$meridio\" | awk '{ printf \"%s (✅ %s / ❌ %s)\\n\", \$1, \$2, \$3 }' | sed ':a;N;\$!ba;s/\\n/ | /g'", returnStdout: true).trim()
223 echo "Meridio: $formatted"
Lionel Jouinc4037892022-11-16 15:53:04 +0100224 badge('meridio-e2e-kind-meridio', 'Meridio', formatted)
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200225 }
226}
227
228def ReportTAPA(success, failure) {
229 return {
230 def tapa_success = sh(script: "echo \"$success\" | grep -oP '(?<=TAPA version: ).*?(?=\\/)' | sort | uniq -c | awk '{ printf \"%s %s 0\\n\", \$2, \$1 }'", returnStdout: true).trim()
231 def tapa_failure = sh(script: "echo \"$failure\" | grep -oP '(?<=TAPA version: ).*?(?=\\/)' | sort | uniq -c | awk '{ printf \"%s 0 %s\\n\", \$2, \$1 }'", returnStdout: true).trim()
Lionel Jouinf26ac952022-10-25 18:38:18 +0200232 def tapa = sh(script: "echo \"$tapa_success\\n$tapa_failure\" | grep -v '^\$' | awk '{ success[\$1] += \$2 ; failure[\$1] += \$3 } END { for(elem in success) print elem, success[elem], failure[elem] }' | sort -k1", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200233 def formatted = sh(script: "echo \"$tapa\" | awk '{ printf \"%s (✅ %s / ❌ %s)\\n\", \$1, \$2, \$3 }' | sed ':a;N;\$!ba;s/\\n/ | /g'", returnStdout: true).trim()
234 echo "TAPA: $formatted"
Lionel Jouinc4037892022-11-16 15:53:04 +0100235 badge('meridio-e2e-kind-tapa', 'TAPA', formatted)
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200236 }
237}
238
239def ReportNSM(success, failure) {
240 return {
241 def nsm_success = sh(script: "echo \"$success\" | grep -oP '(?<=NSM version: ).*?(?=\\/)' | sort | uniq -c | awk '{ printf \"%s %s 0\\n\", \$2, \$1 }'", returnStdout: true).trim()
242 def nsm_failure = sh(script: "echo \"$failure\" | grep -oP '(?<=NSM version: ).*?(?=\\/)' | sort | uniq -c | awk '{ printf \"%s 0 %s\\n\", \$2, \$1 }'", returnStdout: true).trim()
Lionel Jouinf26ac952022-10-25 18:38:18 +0200243 def nsm = sh(script: "echo \"$nsm_success\\n$nsm_failure\" | grep -v '^\$' | awk '{ success[\$1] += \$2 ; failure[\$1] += \$3 } END { for(elem in success) print elem, success[elem], failure[elem] }' | sort -k1", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200244 def formatted = sh(script: "echo \"$nsm\" | awk '{ printf \"%s (✅ %s / ❌ %s)\\n\", \$1, \$2, \$3 }' | sed ':a;N;\$!ba;s/\\n/ | /g'", returnStdout: true).trim()
245 echo "NSM: $formatted"
Lionel Jouinc4037892022-11-16 15:53:04 +0100246 badge('meridio-e2e-kind-nsm', 'NSM', formatted)
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200247 }
248}
249
250def ReportIPFamily(success, failure) {
251 return {
252 def ip_family_success = sh(script: "echo \"$success\" | grep -oP '(?<=IP Family: ).*?(?=\\/)' | sort | uniq -c | awk '{ printf \"%s %s 0\\n\", \$2, \$1 }'", returnStdout: true).trim()
253 def ip_family_failure = sh(script: "echo \"$failure\" | grep -oP '(?<=IP Family: ).*?(?=\\/)' | sort | uniq -c | awk '{ printf \"%s 0 %s\\n\", \$2, \$1 }'", returnStdout: true).trim()
Lionel Jouinf26ac952022-10-25 18:38:18 +0200254 def ip_family = sh(script: "echo \"$ip_family_success\\n$ip_family_failure\" | grep -v '^\$' | awk '{ success[\$1] += \$2 ; failure[\$1] += \$3 } END { for(elem in success) print elem, success[elem], failure[elem] }' | sort -k1", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200255 def formatted = sh(script: "echo \"$ip_family\" | awk '{ printf \"%s (✅ %s / ❌ %s)\\n\", \$1, \$2, \$3 }' | sed ':a;N;\$!ba;s/\\n/ | /g'", returnStdout: true).trim()
256 echo "IP Family: $formatted"
Lionel Jouinc4037892022-11-16 15:53:04 +0100257 badge('meridio-e2e-kind-ip-family', 'IP Family', formatted)
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200258 }
259}
260
261def ReportKubernetes(success, failure) {
262 return {
263 def kubernetes_success = sh(script: "echo \"$success\" | grep -oP '(?<=Kubernetes version: ).*?(?=\\/)' | sort | uniq -c | awk '{ printf \"%s %s 0\\n\", \$2, \$1 }'", returnStdout: true).trim()
264 def kubernetes_failure = sh(script: "echo \"$failure\" | grep -oP '(?<=Kubernetes version: ).*?(?=\\/)' | sort | uniq -c | awk '{ printf \"%s 0 %s\\n\", \$2, \$1 }'", returnStdout: true).trim()
Lionel Jouinf26ac952022-10-25 18:38:18 +0200265 def kubernetes = sh(script: "echo \"$kubernetes_success\\n$kubernetes_failure\" | grep -v '^\$' | awk '{ success[\$1] += \$2 ; failure[\$1] += \$3 } END { for(elem in success) print elem, success[elem], failure[elem] }' | sort -k1", returnStdout: true).trim()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200266 def formatted = sh(script: "echo \"$kubernetes\" | awk '{ printf \"%s (✅ %s / ❌ %s)\\n\", \$1, \$2, \$3 }' | sed ':a;N;\$!ba;s/\\n/ | /g'", returnStdout: true).trim()
267 echo "Kubernetes: $formatted"
Lionel Jouinc4037892022-11-16 15:53:04 +0100268 badge('meridio-e2e-kind-kubernetes', 'Kubernetes', formatted)
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200269 }
270}
271
Lionel Jouinc4037892022-11-16 15:53:04 +0100272def badge(id, subject, message) {
273 addEmbeddableBadgeConfiguration(id: "${id}", subject: "${subject}", color: '#0B1F67', status: "$message")
274 sh """
275 mkdir -p _output
276 echo '{' >> _output/${id}.json
277 echo '"schemaVersion": 1,' >> _output/${id}.json
278 echo '"label": "${subject}",' >> _output/${id}.json
279 echo '"message": "${message}",' >> _output/${id}.json
280 echo '"color": "#0B1F67"' >> _output/${id}.json
281 echo '}' >> _output/${id}.json
282 """
283}
284
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200285// Raise error in Jenkins job
286def Error(e) {
287 return {
288 Cleanup()
289 error e
290 }
291}
292
293// Cleanup directory and kind cluster
294def Cleanup() {
Lionel Jouinc4037892022-11-16 15:53:04 +0100295 def command = 'make -s -C docs/demo/scripts/kind/ clean'
296 ExecSh(command).call()
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200297 cleanWs()
298}
299
300// Execute command
301def ExecSh(command) {
302 return {
Lionel Jouinc4037892022-11-16 15:53:04 +0100303 if (env.DRY_RUN != 'true') {
304 sh """
305 . \${HOME}/.profile
306 ${command}
307 """
308 } else {
309 echo "${command}"
310 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200311 }
312}