blob: 6eed926dcfd937f25e3c9de0a8dbf6ec6c555825 [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
17
18 stage('Clone/Checkout') {
19 git branch: default_branch, url: git_project
20 checkout([
21 $class: 'GitSCM',
22 branches: [[name: current_branch]],
23 extensions: [],
24 userRemoteConfigs: [[
25 refspec: '+refs/pull/*/head:refs/remotes/origin/pr/*',
26 url: git_project
27 ]]
28 ])
29 sh 'git show'
30 }
31 timeout(60) {
32 stage('Environment') {
33 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"
34
35 ExecSh("make -s -C docs/demo/scripts/kind/ KUBERNETES_VERSION=$kubernetes_version NSM_VERSION=$nsm_version KUBERNETES_IP_FAMILY=$ip_family").call()
36 ExecSh("helm install deployments/helm/ --generate-name --create-namespace --namespace red --set trench.name=trench-a --set ipFamily=$ip_family").call()
37 ExecSh("helm install deployments/helm/ --generate-name --create-namespace --namespace red --set trench.name=trench-b --set vlan.id=200 --set ipFamily=$ip_family").call()
38 ExecSh('helm install examples/target/helm/ --generate-name --create-namespace --namespace red --set applicationName=target-a --set default.trench.name=trench-a').call()
39 ExecSh('helm install examples/target/helm/ --generate-name --create-namespace --namespace red --set applicationName=target-b --set default.trench.name=trench-b').call()
40 sh 'sleep 10'
41 ExecSh('kubectl wait --for=condition=Ready pods --all --all-namespaces --timeout=5m').call()
42 }
43 stage('E2E') {
44 echo "Meridio version: $meridio_version"
45 echo "TAPA version: $tapa_version"
46 ExecSh("make e2e E2E_PARAMETERS=\"\$(cat ./test/e2e/environment/kind-helm/$ip_family/config.txt | tr '\\n' ' ')\"").call()
47 }
48 }
49 stage('Cleanup') {
50 Cleanup()
51 }
52 stage('Report') {
53 Report().call()
54 }
55 stage('Next') {
56 Next(next).call()
57 }
58 }
59}
60
61def Next(next) {
62 if (next == 'true') {
63 return {
64 def meridio_version = GetMeridioVersion()
65 def tapa_version = GetTAPAVersion()
66 def nsm_version = GetNSMVersion()
67 def kubernetes_version = GetKubernetesVersion()
68 def ip_family = GetIPFamily()
69 echo "Meridio version: $meridio_version / TAPA version: $tapa_version / NSM version: $nsm_version / IP Family: $ip_family / Kubernetes version: $kubernetes_version"
70 build job: 'meridio-e2e-test-kind', parameters: [
71 string(name: 'NEXT', value: 'true'),
72 string(name: 'MERIDIO_VERSION', value: "$meridio_version"),
73 string(name: 'TAPA_VERSION', value: "$tapa_version"),
74 string(name: 'KUBERNETES_VERSION', value: "$kubernetes_version"),
75 string(name: 'NSM_VERSION', value: "$nsm_version"),
76 string(name: 'IP_FAMILY', value: "$ip_family")
77 ], wait: false
78 }
79 } else {
80 return {
81 Utils.markStageSkippedForConditional('Next')
82 }
83 }
84}
85
86def GetMeridioVersion() {
87 def number_of_versions = sh(script: 'cat test/e2e/environment/kind-helm/test-scope.yaml | yq ".Meridio[]" | wc -l', returnStdout: true).trim()
88 def index_of_version_temp = sh(script: "shuf -i 1-$number_of_versions -n1", returnStdout: true).trim()
89 def index_of_version = sh(script: "expr $index_of_version_temp - 1 || true", returnStdout: true).trim()
90 return sh(script: "cat test/e2e/environment/kind-helm/test-scope.yaml | yq '.Meridio[$index_of_version]'", returnStdout: true).trim()
91}
92
93def GetTAPAVersion() {
94 def number_of_versions = sh(script: 'cat test/e2e/environment/kind-helm/test-scope.yaml | yq ".TAPA[]" | wc -l', returnStdout: true).trim()
95 def index_of_version_temp = sh(script: "shuf -i 1-$number_of_versions -n1", returnStdout: true).trim()
96 def index_of_version = sh(script: "expr $index_of_version_temp - 1 || true", returnStdout: true).trim()
97 return sh(script: "cat test/e2e/environment/kind-helm/test-scope.yaml | yq '.TAPA[$index_of_version]'", returnStdout: true).trim()
98}
99
100def GetNSMVersion() {
101 def number_of_versions = sh(script: 'cat test/e2e/environment/kind-helm/test-scope.yaml | yq ".NSM[]" | wc -l', returnStdout: true).trim()
102 def index_of_version_temp = sh(script: "shuf -i 1-$number_of_versions -n1", returnStdout: true).trim()
103 def index_of_version = sh(script: "expr $index_of_version_temp - 1 || true", returnStdout: true).trim()
104 return sh(script: "cat test/e2e/environment/kind-helm/test-scope.yaml | yq '.NSM[$index_of_version]'", returnStdout: true).trim()
105}
106
107def GetKubernetesVersion() {
108 def number_of_versions = sh(script: 'cat test/e2e/environment/kind-helm/test-scope.yaml | yq ".Kubernetes[]" | wc -l', returnStdout: true).trim()
109 def index_of_version_temp = sh(script: "shuf -i 1-$number_of_versions -n1", returnStdout: true).trim()
110 def index_of_version = sh(script: "expr $index_of_version_temp - 1 || true", returnStdout: true).trim()
111 return sh(script: "cat test/e2e/environment/kind-helm/test-scope.yaml | yq '.Kubernetes[$index_of_version]'", returnStdout: true).trim()
112}
113
114def GetIPFamily() {
115 def number_of_ip_family = sh(script: 'cat test/e2e/environment/kind-helm/test-scope.yaml | yq ".IP-Family[]" | wc -l', returnStdout: true).trim()
116 def index_of_ip_family_temp = sh(script: "shuf -i 1-$number_of_ip_family -n1", returnStdout: true).trim()
117 def index_of_ip_family = sh(script: "expr $index_of_ip_family_temp - 1 || true", returnStdout: true).trim()
118 return sh(script: "cat test/e2e/environment/kind-helm/test-scope.yaml | yq '.IP-Family[$index_of_ip_family]'", returnStdout: true).trim()
119}
120
121// http://JENKINS_URL/job/meridio-e2e-test-kind/api/json?tree=allBuilds[status,timestamp,id,result,description]{0,9}&pretty=true
122def Report() {
123 return {
124 def jenkins_url = 'jenkins.nordix.org'
125
126 def success = sh(script: """
127 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")
128 success=\$(echo \"\$data\" | jq -r '.allBuilds[] | select(.result == \"SUCCESS\") | [.description] | @tsv' | grep -v \"^\$\")
129 echo \$success
130 """, returnStdout: true).trim()
131
132 def failure = sh(script: """
133 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")
134 failure=\$(echo \"\$data\" | jq -r '.allBuilds[] | select(.result == \"FAILURE\") | [.description] | @tsv' | grep -v \"^\$\")
135 echo \$failure
136 """, returnStdout: true).trim()
137
138 ReportMeridio(success, failure).call()
139 ReportTAPA(success, failure).call()
140 ReportNSM(success, failure).call()
141 ReportIPFamily(success, failure).call()
142 ReportKubernetes(success, failure).call()
143 }
144}
145
146def ReportMeridio(success, failure) {
147 return {
148 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()
149 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()
150 def meridio = sh(script: "echo \"$meridio_success\\n$meridio_failure\" | awk '{ success[\$1] += \$2 ; failure[\$1] += \$3 } END { for(elem in success) print elem, success[elem], failure[elem] }' | sort -k1", returnStdout: true).trim()
151 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()
152 echo "Meridio: $formatted"
153 def meridio_badge = addEmbeddableBadgeConfiguration(id: 'meridio-e2e-kind-meridio', subject: 'Meridio', color: '#0B1F67', status: "$formatted")
154 }
155}
156
157def ReportTAPA(success, failure) {
158 return {
159 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()
160 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()
161 def tapa = sh(script: "echo \"$tapa_success\\n$tapa_failure\" | awk '{ success[\$1] += \$2 ; failure[\$1] += \$3 } END { for(elem in success) print elem, success[elem], failure[elem] }' | sort -k1", returnStdout: true).trim()
162 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()
163 echo "TAPA: $formatted"
164 def tapa_badge = addEmbeddableBadgeConfiguration(id: 'meridio-e2e-kind-tapa', subject: 'TAPA', color: '#0B1F67', status: "$formatted")
165 }
166}
167
168def ReportNSM(success, failure) {
169 return {
170 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()
171 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()
172 def nsm = sh(script: "echo \"$nsm_success\\n$nsm_failure\" | awk '{ success[\$1] += \$2 ; failure[\$1] += \$3 } END { for(elem in success) print elem, success[elem], failure[elem] }' | sort -k1", returnStdout: true).trim()
173 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()
174 echo "NSM: $formatted"
175 def nsm_badge = addEmbeddableBadgeConfiguration(id: 'meridio-e2e-kind-nsm', subject: 'NSM', color: '#0B1F67', status: "$formatted")
176 }
177}
178
179def ReportIPFamily(success, failure) {
180 return {
181 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()
182 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()
183 def ip_family = sh(script: "echo \"$ip_family_success\\n$ip_family_failure\" | awk '{ success[\$1] += \$2 ; failure[\$1] += \$3 } END { for(elem in success) print elem, success[elem], failure[elem] }' | sort -k1", returnStdout: true).trim()
184 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()
185 echo "IP Family: $formatted"
186 def ip_family_badge = addEmbeddableBadgeConfiguration(id: 'meridio-e2e-kind-ip-family', subject: 'IP Family', color: '#0B1F67', status: "$formatted")
187 }
188}
189
190def ReportKubernetes(success, failure) {
191 return {
192 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()
193 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()
194 def kubernetes = sh(script: "echo \"$kubernetes_success\\n$kubernetes_failure\" | awk '{ success[\$1] += \$2 ; failure[\$1] += \$3 } END { for(elem in success) print elem, success[elem], failure[elem] }' | sort -k1", returnStdout: true).trim()
195 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()
196 echo "Kubernetes: $formatted"
197 def kubernetes_badge = addEmbeddableBadgeConfiguration(id: 'meridio-e2e-kind-kubernetes', subject: 'Kubernetes', color: '#0B1F67', status: "$formatted")
198 }
199}
200
201// Raise error in Jenkins job
202def Error(e) {
203 return {
204 Cleanup()
205 error e
206 }
207}
208
209// Cleanup directory and kind cluster
210def Cleanup() {
211 ExecSh('make -s -C docs/demo/scripts/kind/ clean').call()
212 cleanWs()
213}
214
215// Execute command
216def ExecSh(command) {
217 return {
218 sh """
219 . \${HOME}/.profile
220 ${command}
221 """
222 }
223}