Lionel Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 1 | import org.jenkinsci.plugins.pipeline.modeldefinition.Utils |
| 2 | |
| 3 | node('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 Jouin | 848fab1 | 2022-10-31 17:32:58 +0100 | [diff] [blame^] | 17 | def number_of_workers = params.NUMBER_OF_WORKERS |
| 18 | def environment_name = params.ENVIRONMENT_NAME |
| 19 | |
| 20 | def seed = params.SEED |
Lionel Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 21 | |
| 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 Jouin | 848fab1 | 2022-10-31 17:32:58 +0100 | [diff] [blame^] | 37 | 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 Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 38 | |
Lionel Jouin | f26ac95 | 2022-10-25 18:38:18 +0200 | [diff] [blame] | 39 | try { |
Lionel Jouin | 848fab1 | 2022-10-31 17:32:58 +0100 | [diff] [blame^] | 40 | 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 Jouin | f26ac95 | 2022-10-25 18:38:18 +0200 | [diff] [blame] | 41 | } catch (Exception e) { |
Lionel Jouin | 848fab1 | 2022-10-31 17:32:58 +0100 | [diff] [blame^] | 42 | unstable 'Environment setup failed' |
| 43 | currentBuild.result = 'FAILURE' |
Lionel Jouin | f26ac95 | 2022-10-25 18:38:18 +0200 | [diff] [blame] | 44 | } |
Lionel Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 45 | } |
| 46 | stage('E2E') { |
Lionel Jouin | 848fab1 | 2022-10-31 17:32:58 +0100 | [diff] [blame^] | 47 | 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 Jouin | f26ac95 | 2022-10-25 18:38:18 +0200 | [diff] [blame] | 56 | } |
Lionel Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 57 | } |
| 58 | } |
Lionel Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 59 | stage('Report') { |
Lionel Jouin | 848fab1 | 2022-10-31 17:32:58 +0100 | [diff] [blame^] | 60 | try { |
| 61 | Report().call() |
| 62 | } catch (Exception e) { |
| 63 | unstable 'Failed to create the report' |
| 64 | } |
Lionel Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 65 | } |
| 66 | stage('Next') { |
Lionel Jouin | 848fab1 | 2022-10-31 17:32:58 +0100 | [diff] [blame^] | 67 | Next(next, number_of_workers, environment_name).call() |
Lionel Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 68 | } |
Lionel Jouin | f77e9e2 | 2022-10-26 13:14:51 +0200 | [diff] [blame] | 69 | stage('Cleanup') { |
| 70 | Cleanup() |
| 71 | } |
Lionel Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
Lionel Jouin | 848fab1 | 2022-10-31 17:32:58 +0100 | [diff] [blame^] | 75 | def Next(next, number_of_workers, environment_name) { |
Lionel Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 76 | 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 Jouin | 848fab1 | 2022-10-31 17:32:58 +0100 | [diff] [blame^] | 83 | 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 Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 85 | 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 Jouin | 848fab1 | 2022-10-31 17:32:58 +0100 | [diff] [blame^] | 91 | 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 Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 95 | ], wait: false |
| 96 | } |
| 97 | } else { |
| 98 | return { |
| 99 | Utils.markStageSkippedForConditional('Next') |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | def 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 | |
| 111 | def 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 | |
| 118 | def 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 | |
| 125 | def 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 | |
| 132 | def 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 Jouin | 848fab1 | 2022-10-31 17:32:58 +0100 | [diff] [blame^] | 139 | def GetSeed() { |
| 140 | return sh(script: 'shuf -i 1-2147483647 -n1', returnStdout: true).trim() |
| 141 | } |
| 142 | |
Lionel Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 143 | // http://JENKINS_URL/job/meridio-e2e-test-kind/api/json?tree=allBuilds[status,timestamp,id,result,description]{0,9}&pretty=true |
| 144 | def Report() { |
| 145 | return { |
| 146 | def jenkins_url = 'jenkins.nordix.org' |
| 147 | |
Lionel Jouin | f26ac95 | 2022-10-25 18:38:18 +0200 | [diff] [blame] | 148 | 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 Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 157 | |
Lionel Jouin | f26ac95 | 2022-10-25 18:38:18 +0200 | [diff] [blame] | 158 | 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 Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 167 | |
| 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 | |
| 176 | def 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 Jouin | f26ac95 | 2022-10-25 18:38:18 +0200 | [diff] [blame] | 180 | 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 Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 181 | 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 | |
| 187 | def 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 Jouin | f26ac95 | 2022-10-25 18:38:18 +0200 | [diff] [blame] | 191 | 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 Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 192 | 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 | |
| 198 | def 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 Jouin | f26ac95 | 2022-10-25 18:38:18 +0200 | [diff] [blame] | 202 | 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 Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 203 | 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 | |
| 209 | def 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 Jouin | f26ac95 | 2022-10-25 18:38:18 +0200 | [diff] [blame] | 213 | 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 Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 214 | 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 | |
| 220 | def 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 Jouin | f26ac95 | 2022-10-25 18:38:18 +0200 | [diff] [blame] | 224 | 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 Jouin | c0ae718 | 2022-10-24 17:28:37 +0200 | [diff] [blame] | 225 | 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 |
| 232 | def Error(e) { |
| 233 | return { |
| 234 | Cleanup() |
| 235 | error e |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | // Cleanup directory and kind cluster |
| 240 | def Cleanup() { |
| 241 | ExecSh('make -s -C docs/demo/scripts/kind/ clean').call() |
| 242 | cleanWs() |
| 243 | } |
| 244 | |
| 245 | // Execute command |
| 246 | def ExecSh(command) { |
| 247 | return { |
| 248 | sh """ |
| 249 | . \${HOME}/.profile |
| 250 | ${command} |
| 251 | """ |
| 252 | } |
| 253 | } |