blob: 04f7f36bf09c7e0b1ba18dea40b3796cd0b89e41 [file] [log] [blame]
Lionel Jouinc0ae7182022-10-24 17:28:37 +02001import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
2
3node('nordix-nsm-build-ubuntu1804') {
4 build_number = env.BUILD_NUMBER
5 workspace = env.WORKSPACE
6 ws("${workspace}/${build_number}") {
7 def git_project = params.GIT_PROJECT
8 def current_branch = params.CURRENT_BRANCH
9 def default_branch = params.DEFAULT_BRANCH
10 def next = params.NEXT
11
12 def meridio_version = params.MERIDIO_VERSION
13 def tapa_version = params.TAPA_VERSION
14 def kubernetes_version = params.KUBERNETES_VERSION
15 def nsm_version = params.NSM_VERSION
16 def ip_family = params.IP_FAMILY
Lionel Jouin848fab12022-10-31 17:32:58 +010017 def number_of_workers = params.NUMBER_OF_WORKERS
18 def environment_name = params.ENVIRONMENT_NAME
19
20 def seed = params.SEED
Lionel Jouinc0ae7182022-10-24 17:28:37 +020021
22 stage('Clone/Checkout') {
23 git branch: default_branch, url: git_project
24 checkout([
25 $class: 'GitSCM',
26 branches: [[name: current_branch]],
27 extensions: [],
28 userRemoteConfigs: [[
29 refspec: '+refs/pull/*/head:refs/remotes/origin/pr/*',
30 url: git_project
31 ]]
32 ])
33 sh 'git show'
34 }
35 timeout(60) {
36 stage('Environment') {
Lionel Jouin848fab12022-10-31 17:32:58 +010037 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 +020038
Lionel Jouinf26ac952022-10-25 18:38:18 +020039 try {
Lionel Jouin848fab12022-10-31 17:32:58 +010040 ExecSh("make -s -C test/e2e/environment/$environment_name/ KUBERNETES_VERSION=$kubernetes_version NSM_VERSION=$nsm_version KUBERNETES_IP_FAMILY=$ip_family KUBERNETES_WORKERS=$number_of_workers").call()
Lionel Jouinf26ac952022-10-25 18:38:18 +020041 } catch (Exception e) {
Lionel Jouin848fab12022-10-31 17:32:58 +010042 unstable 'Environment setup failed'
43 currentBuild.result = 'FAILURE'
Lionel Jouinf26ac952022-10-25 18:38:18 +020044 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +020045 }
46 stage('E2E') {
Lionel Jouin848fab12022-10-31 17:32:58 +010047 if (currentBuild.result != 'FAILURE') {
48 try {
49 ExecSh("make e2e E2E_PARAMETERS=\"\$(cat ./test/e2e/environment/$environment_name/$ip_family/config.txt | tr '\\n' ' ')\" E2E_SEED=$seed").call()
50 } catch (Exception e) {
51 unstable 'E2E Tests failed'
52 currentBuild.result = 'FAILURE'
53 }
54 } else {
55 Utils.markStageSkippedForConditional('E2E')
Lionel Jouinf26ac952022-10-25 18:38:18 +020056 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +020057 }
58 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +020059 stage('Report') {
Lionel Jouin848fab12022-10-31 17:32:58 +010060 try {
61 Report().call()
62 } catch (Exception e) {
63 unstable 'Failed to create the report'
64 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +020065 }
66 stage('Next') {
Lionel Jouin848fab12022-10-31 17:32:58 +010067 Next(next, number_of_workers, environment_name).call()
Lionel Jouinc0ae7182022-10-24 17:28:37 +020068 }
Lionel Jouinf77e9e22022-10-26 13:14:51 +020069 stage('Cleanup') {
70 Cleanup()
71 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +020072 }
73}
74
Lionel Jouin848fab12022-10-31 17:32:58 +010075def Next(next, number_of_workers, environment_name) {
Lionel Jouinc0ae7182022-10-24 17:28:37 +020076 if (next == 'true') {
77 return {
78 def meridio_version = GetMeridioVersion()
79 def tapa_version = GetTAPAVersion()
80 def nsm_version = GetNSMVersion()
81 def kubernetes_version = GetKubernetesVersion()
82 def ip_family = GetIPFamily()
Lionel Jouin848fab12022-10-31 17:32:58 +010083 def seed = GetSeed()
84 echo "Meridio version: $meridio_version / TAPA version: $tapa_version / NSM version: $nsm_version / IP Family: $ip_family / Kubernetes version: $kubernetes_version / Seed: $seed"
Lionel Jouinc0ae7182022-10-24 17:28:37 +020085 build job: 'meridio-e2e-test-kind', parameters: [
86 string(name: 'NEXT', value: 'true'),
87 string(name: 'MERIDIO_VERSION', value: "$meridio_version"),
88 string(name: 'TAPA_VERSION', value: "$tapa_version"),
89 string(name: 'KUBERNETES_VERSION', value: "$kubernetes_version"),
90 string(name: 'NSM_VERSION', value: "$nsm_version"),
Lionel Jouin848fab12022-10-31 17:32:58 +010091 string(name: 'IP_FAMILY', value: "$ip_family"),
92 string(name: 'NUMBER_OF_WORKERS', value: "$number_of_workers"),
93 string(name: 'ENVIRONMENT_NAME', value: "$environment_name"),
94 string(name: 'SEED', value: "$seed")
Lionel Jouinc0ae7182022-10-24 17:28:37 +020095 ], wait: false
96 }
97 } else {
98 return {
99 Utils.markStageSkippedForConditional('Next')
100 }
101 }
102}
103
104def GetMeridioVersion() {
105 def number_of_versions = sh(script: 'cat test/e2e/environment/kind-helm/test-scope.yaml | yq ".Meridio[]" | wc -l', returnStdout: true).trim()
106 def index_of_version_temp = sh(script: "shuf -i 1-$number_of_versions -n1", returnStdout: true).trim()
107 def index_of_version = sh(script: "expr $index_of_version_temp - 1 || true", returnStdout: true).trim()
108 return sh(script: "cat test/e2e/environment/kind-helm/test-scope.yaml | yq '.Meridio[$index_of_version]'", returnStdout: true).trim()
109}
110
111def GetTAPAVersion() {
112 def number_of_versions = sh(script: 'cat test/e2e/environment/kind-helm/test-scope.yaml | yq ".TAPA[]" | wc -l', returnStdout: true).trim()
113 def index_of_version_temp = sh(script: "shuf -i 1-$number_of_versions -n1", returnStdout: true).trim()
114 def index_of_version = sh(script: "expr $index_of_version_temp - 1 || true", returnStdout: true).trim()
115 return sh(script: "cat test/e2e/environment/kind-helm/test-scope.yaml | yq '.TAPA[$index_of_version]'", returnStdout: true).trim()
116}
117
118def GetNSMVersion() {
119 def number_of_versions = sh(script: 'cat test/e2e/environment/kind-helm/test-scope.yaml | yq ".NSM[]" | wc -l', returnStdout: true).trim()
120 def index_of_version_temp = sh(script: "shuf -i 1-$number_of_versions -n1", returnStdout: true).trim()
121 def index_of_version = sh(script: "expr $index_of_version_temp - 1 || true", returnStdout: true).trim()
122 return sh(script: "cat test/e2e/environment/kind-helm/test-scope.yaml | yq '.NSM[$index_of_version]'", returnStdout: true).trim()
123}
124
125def GetKubernetesVersion() {
126 def number_of_versions = sh(script: 'cat test/e2e/environment/kind-helm/test-scope.yaml | yq ".Kubernetes[]" | wc -l', returnStdout: true).trim()
127 def index_of_version_temp = sh(script: "shuf -i 1-$number_of_versions -n1", returnStdout: true).trim()
128 def index_of_version = sh(script: "expr $index_of_version_temp - 1 || true", returnStdout: true).trim()
129 return sh(script: "cat test/e2e/environment/kind-helm/test-scope.yaml | yq '.Kubernetes[$index_of_version]'", returnStdout: true).trim()
130}
131
132def GetIPFamily() {
133 def number_of_ip_family = sh(script: 'cat test/e2e/environment/kind-helm/test-scope.yaml | yq ".IP-Family[]" | wc -l', returnStdout: true).trim()
134 def index_of_ip_family_temp = sh(script: "shuf -i 1-$number_of_ip_family -n1", returnStdout: true).trim()
135 def index_of_ip_family = sh(script: "expr $index_of_ip_family_temp - 1 || true", returnStdout: true).trim()
136 return sh(script: "cat test/e2e/environment/kind-helm/test-scope.yaml | yq '.IP-Family[$index_of_ip_family]'", returnStdout: true).trim()
137}
138
Lionel Jouin848fab12022-10-31 17:32:58 +0100139def GetSeed() {
140 return sh(script: 'shuf -i 1-2147483647 -n1', returnStdout: true).trim()
141}
142
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200143// http://JENKINS_URL/job/meridio-e2e-test-kind/api/json?tree=allBuilds[status,timestamp,id,result,description]{0,9}&pretty=true
144def Report() {
145 return {
146 def jenkins_url = 'jenkins.nordix.org'
147
Lionel Jouinf26ac952022-10-25 18:38:18 +0200148 def success = ''
149 try {
150 success = sh(script: """
151 data=\$(curl -s -L "http://$jenkins_url/job/meridio-e2e-test-kind/api/json?tree=allBuilds\\[status,timestamp,id,result,description\\]\\{0,999\\}&pretty=true")
152 success=\$(echo \"\$data\" | jq -r '.allBuilds[] | select(.result == \"SUCCESS\") | [.description] | @tsv' | grep -v \"^\$\")
153 echo \$success
154 """, returnStdout: true).trim()
155 } catch (Exception e) {
156 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200157
Lionel Jouinf26ac952022-10-25 18:38:18 +0200158 def failure = ''
159 try {
160 failure = sh(script: """
161 data=\$(curl -s -L "http://$jenkins_url/job/meridio-e2e-test-kind/api/json?tree=allBuilds\\[status,timestamp,id,result,description\\]\\{0,999\\}&pretty=true")
162 failure=\$(echo \"\$data\" | jq -r '.allBuilds[] | select(.result == \"FAILURE\") | [.description] | @tsv' | grep -v \"^\$\")
163 echo \$failure
164 """, returnStdout: true).trim()
165 } catch (Exception e) {
166 }
Lionel Jouinc0ae7182022-10-24 17:28:37 +0200167
168 ReportMeridio(success, failure).call()
169 ReportTAPA(success, failure).call()
170 ReportNSM(success, failure).call()
171 ReportIPFamily(success, failure).call()
172 ReportKubernetes(success, failure).call()
173 }
174}
175
176def ReportMeridio(success, failure) {
177 return {
178 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()
179 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 +0200180 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 +0200181 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()
182 echo "Meridio: $formatted"
183 def meridio_badge = addEmbeddableBadgeConfiguration(id: 'meridio-e2e-kind-meridio', subject: 'Meridio', color: '#0B1F67', status: "$formatted")
184 }
185}
186
187def ReportTAPA(success, failure) {
188 return {
189 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()
190 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 +0200191 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 +0200192 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()
193 echo "TAPA: $formatted"
194 def tapa_badge = addEmbeddableBadgeConfiguration(id: 'meridio-e2e-kind-tapa', subject: 'TAPA', color: '#0B1F67', status: "$formatted")
195 }
196}
197
198def ReportNSM(success, failure) {
199 return {
200 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()
201 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 +0200202 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 +0200203 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()
204 echo "NSM: $formatted"
205 def nsm_badge = addEmbeddableBadgeConfiguration(id: 'meridio-e2e-kind-nsm', subject: 'NSM', color: '#0B1F67', status: "$formatted")
206 }
207}
208
209def ReportIPFamily(success, failure) {
210 return {
211 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()
212 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 +0200213 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 +0200214 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()
215 echo "IP Family: $formatted"
216 def ip_family_badge = addEmbeddableBadgeConfiguration(id: 'meridio-e2e-kind-ip-family', subject: 'IP Family', color: '#0B1F67', status: "$formatted")
217 }
218}
219
220def ReportKubernetes(success, failure) {
221 return {
222 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()
223 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 +0200224 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 +0200225 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()
226 echo "Kubernetes: $formatted"
227 def kubernetes_badge = addEmbeddableBadgeConfiguration(id: 'meridio-e2e-kind-kubernetes', subject: 'Kubernetes', color: '#0B1F67', status: "$formatted")
228 }
229}
230
231// Raise error in Jenkins job
232def Error(e) {
233 return {
234 Cleanup()
235 error e
236 }
237}
238
239// Cleanup directory and kind cluster
240def Cleanup() {
241 ExecSh('make -s -C docs/demo/scripts/kind/ clean').call()
242 cleanWs()
243}
244
245// Execute command
246def ExecSh(command) {
247 return {
248 sh """
249 . \${HOME}/.profile
250 ${command}
251 """
252 }
253}