Jenkinsfile-GitLab-Docker 27.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/groovy
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

//-------------------------------------------------------------------------------

// Location of the CN executor node
def cn_ci_host = params.Host_CN_CI_Server

// for lock
def cn_ci_resource = params.DockerContainers

Mohammed Ismail's avatar
Mohammed Ismail committed
31
32
33
34
35
36
37
38
39
40
// Location of the Remote Ubuntu18 CN executor
def rem_u18_host_flag = false
def rem_u18_host = ""
def rem_u18_host_user = ""

// Location of the Remote RHEL CN executor
def rem_rhel_host_flag = false
def rem_rhel_host = ""
def rem_rhel_host_user = ""
def rem_rhel8_resource = params.PodmanContainers
41
42
43
44
45

// Tags/Branches to use
def nrf_tag = "develop"
def nrf_branch = "develop"

Mohammed Ismail's avatar
Mohammed Ismail committed
46
47
48
49
// We are using a base image to speed up CI build.
// This base image is potentially subject to changes over time.
def NRF_BASE_IMAGE_TAG = params.NrfBaseImageTag

50
51
52
// Merge Request Link
def gitlabMergeRequestLink

53
54
55
56
57
58
59
60
61
62
63
64
65
//-------------------------------------------------------------------------------
// Pipeline start
pipeline {
  agent {
    label cn_ci_host
  }
  options {
    disableConcurrentBuilds()
    timestamps()
    ansiColor('xterm')
    lock(cn_ci_resource)
    gitLabConnection('OAI GitLab')
    gitlabBuilds(builds: [
Mohammed Ismail's avatar
Mohammed Ismail committed
66
67
      "Build U18 NRF Image",
      "Build RHEL8 NRF Image",
68
      "Static Code Analysis",
69
      "Code Formatting Checker",
70
71
72
      "Bracket Test with DsTester",
      "Test with DsTester on Docker environment",
      "Test with DsTester on OC environment"
73
74
75
76
77
78
79
80
81
82
83
84
85
    ])
  }

  stages {
    stage ('Verify Parameters') {
      steps {
        script {
          echo '\u2705 \u001B[32mVerify Parameters\u001B[0m'

          JOB_TIMESTAMP = sh returnStdout: true, script: 'date --utc --rfc-3339=seconds | sed -e "s#+00:00##"'
          JOB_TIMESTAMP = JOB_TIMESTAMP.trim()

          if (params.Host_CN_CI_2nd_Server_Flag != null) {
Mohammed Ismail's avatar
Mohammed Ismail committed
86
87
88
89
            rem_u18_host_flag = params.Host_CN_CI_2nd_Server_Flag
            if (rem_u18_host_flag) {
              rem_u18_host = params.Host_CN_CI_2nd_Server
              rem_u18_host_user = params.Host_CN_CI_2nd_Server_Login
90
              echo "1st Node   is ${NODE_NAME}"
Mohammed Ismail's avatar
Mohammed Ismail committed
91
              echo "2nd Node   is ${rem_u18_host}"
92
            } else {
Mohammed Ismail's avatar
Mohammed Ismail committed
93
              echo "U18 Node   is ${NODE_NAME}"
94
95
96
97
            }
          } else {
            echo "Node       is ${NODE_NAME}"
          }
Mohammed Ismail's avatar
Mohammed Ismail committed
98
99
100
101
102
103
104
105
          if (params.Remote_RHEL_Server_Flag != null) {
            rem_rhel_host_flag = params.Remote_RHEL_Server_Flag
            if (rem_rhel_host_flag) {
              rem_rhel_host = params.Remote_RHEL_Server_Name
              rem_rhel_host_user = params.Remote_RHEL_Server_Login
              echo "RHEL Node  is ${rem_rhel_host}"
            }
          }
106
          echo "Git URL    is ${GIT_URL}"
Mohammed Ismail's avatar
Mohammed Ismail committed
107
108
109

          if ("MERGE".equals(env.gitlabActionType)) {
            try {
Mohammed Ismail's avatar
Mohammed Ismail committed
110
              myShCmd('docker image inspect --format=\'Size = {{.Size}} bytes\' oai-nrf-base:' + NRF_BASE_IMAGE_TAG, rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
Mohammed Ismail's avatar
Mohammed Ismail committed
111
112
113
114
115
116
            } catch (Exception e) {
              currentBuild.result = 'FAILURE'
              echo '\u26D4 \u001B[31mBase Image does not exist\u001B[0m'
              error "Stopping pipeline!"
            }
          }
117
118
119
120
121
122
123
124
        }
      }
    }
    stage ('Prepare Source Code') {
      steps {
        script {
          sh "git clean -x -d -f > /dev/null 2>&1"
          if ("MERGE".equals(env.gitlabActionType)) {
125
126
            gitlabMergeRequestLink = sh returnStdout: true, script: "curl --silent 'https://gitlab.eurecom.fr/api/v4/projects/oai%2Fcn5g%2Foai-cn5g-nrf/merge_requests/${env.gitlabMergeRequestIid}' | jq .web_url | sed 's#\"##g'"
            gitlabMergeRequestLink = gitlabMergeRequestLink.trim()
Mohammed Ismail's avatar
Mohammed Ismail committed
127
128
129
130
            echo "========= THIS IS A MERGE REQUEST =========="
            echo "MR ID       is ${env.gitlabMergeRequestIid}"
            echo "MR LINK     is ${gitlabMergeRequestLink}"
            echo "MR TITLE    is ${env.gitlabMergeRequestTitle}"
131
132
            gitCommitAuthorEmailAddr = env.gitlabUserEmail
            echo "GitLab Usermail is ${gitCommitAuthorEmailAddr}"
Mohammed Ismail's avatar
Mohammed Ismail committed
133
134
135
            sh "git fetch --prune --unshallow"
            shortenShaOne = sh returnStdout: true, script: 'git log -1 --pretty=format:"%h" ' + env.gitlabMergeRequestLastCommit
            shortenShaOne = shortenShaOne.trim()
136
            sh "./ci-scripts/doGitLabMerge.sh --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
Mohammed Ismail's avatar
Mohammed Ismail committed
137
            sh "sleep 10"
138
            nrf_tag = "ci-tmp"
Mohammed Ismail's avatar
Mohammed Ismail committed
139
            rhel_nrf_tag = 'ci-tmp-pr-' + env.gitlabMergeRequestIid + '-' + shortenShaOne
140
            nrf_branch = env.gitlabSourceBranch
Mohammed Ismail's avatar
Mohammed Ismail committed
141
            echo "MR TAG      is ${rhel_nrf_tag}"
142
          } else {
Mohammed Ismail's avatar
Mohammed Ismail committed
143
            echo "======== THIS IS A PUSH REQUEST ========"
144
145
146
147
148
149
150
151
152
            echo "Git Branch      is ${GIT_BRANCH}"
            echo "Git Commit      is ${GIT_COMMIT}"
            gitCommitAuthorEmailAddr = sh returnStdout: true, script: 'git log -n1 --pretty=format:%ae ${GIT_COMMIT}'
            gitCommitAuthorEmailAddr = gitCommitAuthorEmailAddr.trim()
            echo "GitLab Usermail is ${gitCommitAuthorEmailAddr}"
            sh "git log -n1 --pretty=format:\"%s\" > .git/CI_COMMIT_MSG"
          }
          sh "tar -cjhf /tmp/openair-nrf.tar.bz2 ."
          sh "mv /tmp/openair-nrf.tar.bz2 ."
Mohammed Ismail's avatar
Mohammed Ismail committed
153
154
155
          copyTo2ndServer('openair-nrf.tar.bz2', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
          copyTo2ndServer('openair-nrf.tar.bz2', rem_rhel_host_flag, rem_rhel_host_user, rem_rhel_host)
          sh "mkdir -p archives/oai-nrf-cfg"
156
157
158
159
160
161
162
163
164
165
166
167
168
169
        }
      }
      post {
        failure {
          script {
            def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): Merge Conflicts -- Cannot perform CI"
            addGitLabMRComment comment: message
            currentBuild.result = 'FAILURE'
          }
        }
      }
    }
    stage('Build Core Network Function') {
      parallel {
Mohammed Ismail's avatar
Mohammed Ismail committed
170
        stage ('Build U18 NRF Image') {
171
172
          steps {
            script {
Mohammed Ismail's avatar
Mohammed Ismail committed
173
174
              gitlabCommitStatus(name: "Build U18 NRF Image") {
                myShCmd('docker image prune --force', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
175
176
177
178
                if ("PUSH".equals(env.gitlabActionType)) {
                  // Currently this pipeline only runs for pushes to `develop` branch
                  // First clean image registry
                  try {
Mohammed Ismail's avatar
Mohammed Ismail committed
179
                    myShCmd('docker image rm oai-nrf:develop', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
180
181
182
                  } catch (Exception e) {
                    echo "Maybe a previous build went wrong"
                  }
Mohammed Ismail's avatar
Mohammed Ismail committed
183
                  // In case of push to `develop` branch we build from scratch
184
                  myShCmd('docker build --no-cache --target oai-nrf --tag oai-nrf:' + nrf_tag + ' --file docker/Dockerfile.nrf.ubuntu18 --build-arg NEEDED_GIT_PROXY="http://proxy.eurecom.fr:8080" . > archives/nrf_docker_image_build.log 2>&1', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
Mohammed Ismail's avatar
Mohammed Ismail committed
185
186
187
188
189
                }
                if ("MERGE".equals(env.gitlabActionType)) {
                  try {
                    // Checking if the CI Base image is still there.
                    // If the inspect command fails, it's not there. If it passes, let remove tag.
Mohammed Ismail's avatar
Mohammed Ismail committed
190
191
                    myShCmd('docker image inspect oai-nrf-base:latest > /dev/null 2>&1', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
                    myShCmd('docker rmi oai-nrf-base:latest', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
Mohammed Ismail's avatar
Mohammed Ismail committed
192
193
194
195
                  } catch (Exception e) {
                    echo 'No need to remove the CI base image'
                  }
                  // "latest" is the tag used in the docker file.
Mohammed Ismail's avatar
Mohammed Ismail committed
196
197
                  myShCmd('docker image tag oai-nrf-base:' + NRF_BASE_IMAGE_TAG + ' oai-nrf-base:latest', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
                  myShCmd('docker build --no-cache --target oai-nrf --tag oai-nrf:' + nrf_tag + ' --file ci-scripts/docker/Dockerfile.ci.ubuntu.18.04 . > archives/nrf_docker_image_build.log 2>&1', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
198
                }
Mohammed Ismail's avatar
Mohammed Ismail committed
199
                myShCmd('docker image ls >> archives/nrf_docker_image_build.log', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
200
201
202
203
204
205
              }
            }
          }
          post {
            always {
              script {
Mohammed Ismail's avatar
Mohammed Ismail committed
206
                copyFrom2ndServer('archives/nrf_docker_image_build.log', 'archives', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
207
208
209
210
211
212
213
214
215
216
              }
            }
            success {
              sh "echo 'OAI-NRF DOCKER IMAGE BUILD: OK' >> archives/nrf_docker_image_build.log"
            }
            unsuccessful {
              sh "echo 'OAI-NRF DOCKER IMAGE BUILD: KO' >> archives/nrf_docker_image_build.log"
            }
          }
        }
Mohammed Ismail's avatar
Mohammed Ismail committed
217
218
219
220
221
222

        stage ('Build RHEL8 NRF Image') {
          when { expression {rem_rhel_host_flag} }
          steps {
            lock (rem_rhel8_resource) {
              script {
223
                gitlabCommitStatus(name: "Build RHEL8 NRF Image") {
Mohammed Ismail's avatar
Mohammed Ismail committed
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
                  if ("PUSH".equals(env.gitlabActionType)) {
                    // Currently this pipeline only runs for pushes to `develop` branch
                    // First clean image registry
                    try {
                      myShCmd('sudo podman image rm oai-nrf:develop || true', rem_rhel_host_flag, rem_rhel_host_user, rem_rhel_host)
                    } catch (Exception e) {
                      echo "Maybe a previous build went wrong"
                    } 
                  } else {
                    // In case we forgot during a previous run
                    myShCmd('sudo podman image rm oai-nrf:' + nrf_tag + ' || true', rem_rhel_host_flag, rem_rhel_host_user, rem_rhel_host)
                  }
                  myShCmd('sudo podman image prune --force', rem_rhel_host_flag, rem_rhel_host_user, rem_rhel_host)
                  // Copy the RHEL Host certificates for building
                  myShCmd('mkdir -p tmp/ca tmp/entitlement', rem_rhel_host_flag, rem_rhel_host_user, rem_rhel_host)
                  myShCmd('cp /etc/pki/entitlement/*pem tmp/entitlement', rem_rhel_host_flag, rem_rhel_host_user, rem_rhel_host)
                  myShCmd('sudo cp /etc/rhsm/ca/redhat-uep.pem tmp/ca', rem_rhel_host_flag, rem_rhel_host_user, rem_rhel_host)
241
                  myShCmd('sudo podman build --no-cache --target oai-nrf --tag oai-nrf:' + nrf_tag + ' --file docker/Dockerfile.nrf.rhel8 --build-arg NEEDED_GIT_PROXY="http://proxy.eurecom.fr:8080" . > archives/nrf_podman_image_build.log 2>&1', rem_rhel_host_flag, rem_rhel_host_user, rem_rhel_host)
Mohammed Ismail's avatar
Mohammed Ismail committed
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
                  myShCmd('sudo podman image ls >> archives/nrf_podman_image_build.log', rem_rhel_host_flag, rem_rhel_host_user, rem_rhel_host)
                  if ("MERGE".equals(env.gitlabActionType)) {
                    myShCmd('sudo podman image tag oai-nrf:' + nrf_tag + ' oai-nrf:' + rhel_nrf_tag, rem_rhel_host_flag, rem_rhel_host_user, rem_rhel_host)
                  }
                }
              }
            }
          }
          post {
            always {
              script {
                copyFrom2ndServer('archives/nrf_podman_image_build.log', 'archives', rem_rhel_host_flag, rem_rhel_host_user, rem_rhel_host)
              }
            }
            success {
              sh "echo 'OAI-NRF PODMAN RHEL8 IMAGE BUILD: OK' >> archives/nrf_podman_image_build.log"
            }
            unsuccessful {
              sh "echo 'OAI-NRF PODMAN RHEL8 IMAGE BUILD: KO' >> archives/nrf_podman_image_build.log"
            }
          }
        }
264
265
266
267
268
269
        // Running CPPCHECK in parallel to gain time
        stage ('Static Code Analysis') {
          steps {
            script {
              gitlabCommitStatus(name: "Static Code Analysis") {
                // Running on xenial to have 1.72 version of cppcheck
Mohammed Ismail's avatar
Mohammed Ismail committed
270
271
272
                myShCmd('docker run --name ci-cn-cppcheck -d ubuntu:xenial /bin/bash -c "sleep infinity"', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
                myShCmd('docker exec ci-cn-cppcheck /bin/bash -c "apt-get update && apt-get upgrade --yes" > archives/cppcheck_install.log', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
                myShCmd('docker exec ci-cn-cppcheck /bin/bash -c "apt-get install --yes cppcheck bzip2" >> archives/cppcheck_install.log', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
273

Mohammed Ismail's avatar
Mohammed Ismail committed
274
275
276
                myShCmd('docker cp ./openair-nrf.tar.bz2 ci-cn-cppcheck:/home', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
                myShCmd('docker exec ci-cn-cppcheck /bin/bash -c "cd /home && tar -xjf openair-nrf.tar.bz2"', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
                myShCmd('docker exec ci-cn-cppcheck /bin/bash -c "rm -f /home/openair-nrf.tar.bz2"', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
277

Mohammed Ismail's avatar
Mohammed Ismail committed
278
                myShCmd('docker exec ci-cn-cppcheck /bin/bash -c "cd /home && cppcheck --enable=warning --force --xml --xml-version=2 --suppressions-list=ci-scripts/cppcheck_suppressions.list src 2> cppcheck.xml 1> cppcheck_build.log"', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
279
280
281
282
283
284
              }
            }
          }
          post {
            always {
              script {
Mohammed Ismail's avatar
Mohammed Ismail committed
285
286
287
                myShCmd('docker cp ci-cn-cppcheck:/home/cppcheck.xml archives', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
                myShCmd('docker cp ci-cn-cppcheck:/home/cppcheck_build.log archives', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
                copyFrom2ndServer('archives/cppcheck*.*', 'archives', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
288
                // no need to keep the cppcheck container
Mohammed Ismail's avatar
Mohammed Ismail committed
289
                myShCmd('docker rm -f ci-cn-cppcheck', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
              }
            }
            success {
              sh "echo 'CPPCHECK: OK' >> archives/cppcheck_install.log"
            }
            unsuccessful {
              sh "echo 'CPPCHECK: KO' >> archives/cppcheck_install.log"
            }
          }
        }
        // Running CLANG-FORMATTING check in parallel to gain time
        stage ('Code Formatting Checker') {
          steps {
            script {
              gitlabCommitStatus(name: "Code Formatting Checker") {
Mohammed Ismail's avatar
Mohammed Ismail committed
305
306
307
                myShCmd('docker run --name ci-cn-clang-formatter -d ubuntu:bionic /bin/bash -c "sleep infinity"', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
                myShCmd('docker exec ci-cn-clang-formatter /bin/bash -c "apt-get update && apt-get upgrade --yes" > archives/clang_format_install.log', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
                myShCmd('docker exec ci-cn-clang-formatter /bin/bash -c "apt-get install --yes git tree bzip2" >> archives/clang_format_install.log', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
308

Mohammed Ismail's avatar
Mohammed Ismail committed
309
310
311
                myShCmd('docker cp ./openair-nrf.tar.bz2 ci-cn-clang-formatter:/home', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
                myShCmd('docker exec ci-cn-clang-formatter /bin/bash -c "cd /home && tar -xjf openair-nrf.tar.bz2"', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
                myShCmd('docker exec ci-cn-clang-formatter /bin/bash -c "rm -f /home/openair-nrf.tar.bz2"', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
312
313

                // We install a dedicated version (installed on our CI server).
Mohammed Ismail's avatar
Mohammed Ismail committed
314
                myShCmd('docker cp /opt/clang-format/9.0.0/bin/clang-format ci-cn-clang-formatter:/usr/local/bin', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
315
                if ("MERGE".equals(env.gitlabActionType)) {
Mohammed Ismail's avatar
Mohammed Ismail committed
316
                  myShCmd('docker exec ci-cn-clang-formatter /bin/bash -c "cd /home && ./ci-scripts/checkCodingFormattingRules.sh --src-branch ' + env.gitlabSourceBranch +' --target-branch ' + env.gitlabTargetBranch + '"', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
317
                } else {
Mohammed Ismail's avatar
Mohammed Ismail committed
318
                  myShCmd('docker exec ci-cn-clang-formatter /bin/bash -c "cd /home && ./ci-scripts/checkCodingFormattingRules.sh"', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
319
320
321
322
323
324
325
                }
              }
            }
          }
          post {
            always {
              script {
Mohammed Ismail's avatar
Mohammed Ismail committed
326
                myShCmd('docker cp ci-cn-clang-formatter:/home/src/oai_rules_result.txt src', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
327
328
                // May not have been generated
                try {
Mohammed Ismail's avatar
Mohammed Ismail committed
329
                  myShCmd('docker cp ci-cn-clang-formatter:/home/src/oai_rules_result_list.txt src', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
330
331
332
                } catch (Exception e) {
                  echo "Failed to copy src/oai_rules_result_list.txt! It may not have been generated. That's OK!"
                }
Mohammed Ismail's avatar
Mohammed Ismail committed
333
334
                copyFrom2ndServer('archives/clang_format*.*', 'archives', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
                copyFrom2ndServer('src/oai_rules*.*', 'src', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
335
                // no need to keep the clang-formatter container
Mohammed Ismail's avatar
Mohammed Ismail committed
336
                myShCmd('docker rm -f ci-cn-clang-formatter', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
337
338
339
340
341
342
              }
            }
          }
        }
      }
    }
ismail's avatar
ismail committed
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
    stage ('Bracket Testing with DsTester') {
      steps {
        script {
          gitlabCommitStatus(name: "Bracket Test with DsTester") {
            localStatus = build job: params.NRF_BT_PipelineName,
              parameters: [
                string(name: 'NRF_TAG', value: String.valueOf(nrf_tag))
              ], propagate: false
            localResult = localStatus.getResult()

            if (localStatus.resultIsBetterOrEqualTo('SUCCESS')) {
              echo "Bracket Test Job is OK"
            } else {
              echo "Bracket Test Job is KO"
              sh "ci-scripts/fail.sh"
            }
          }
        }
      }
      post {
        always {
          script {
Raphael Defosseux's avatar
Raphael Defosseux committed
365
            copyArtifacts(projectName: params.NRF_BT_PipelineName,
ismail's avatar
ismail committed
366
367
368
369
370
371
                          filter: '*_results_oai_nrf_bt.html',
                          selector: lastCompleted())
          }
        }
      }
    }
372
373
374
375
376
377
378
379
380
381
382
383
    stage('Testing whole 5g Core Network Functions') {
      parallel {
        stage ('Testing in CN-5G-FED Docker environment') {
          steps {
            script {
              gitlabCommitStatus(name: "Test with DsTester on Docker environment") {
                localStatus = build job: params.CN5G_FED_PipelineName,
                  parameters: [
                    string(name: 'NRF_TAG', value: String.valueOf(nrf_tag)),
                    string(name: 'NRF_BRANCH', value: String.valueOf(nrf_branch))
                  ], propagate: false
                localResult = localStatus.getResult()
384

385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
                if (localStatus.resultIsBetterOrEqualTo('SUCCESS')) {
                  echo "Docker Federation Test Job is OK"
                } else {
                  echo "Docker Federation Test Job is KO"
                  sh "ci-scripts/fail.sh"
                }
              }
            }
          }
          post {
            always {
              script {
                copyArtifacts(projectName: params.CN5G_FED_PipelineName,
                              filter: '*_results_oai_cn5g.html',
                              selector: lastCompleted())
              }
401
402
403
            }
          }
        }
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
        stage ('Testing in CN-5G-FED environment OC environment') {
          steps {
            script {
              gitlabCommitStatus(name: "Test with DsTester on OC environment") {
                localStatus = build job: params.CN5G_FED_OC_PipelineName,
                  parameters: [
                    string(name: 'NRF_TAG', value: String.valueOf(nrf_tag)),
                    string(name: 'NRF_BRANCH', value: String.valueOf(nrf_branch))
                  ], propagate: false
                localResult = localStatus.getResult()

                if (localStatus.resultIsBetterOrEqualTo('SUCCESS')) {
                  echo "OC Federation Test Job is OK"
                } else {
                  echo "OC Federation Test Job is KO"
                  sh "ci-scripts/fail.sh"
                }
              }
            }
          }
          post {
            always {
              script {
                copyArtifacts(projectName: params.CN5G_FED_OC_PipelineName,
                              filter: '*_results_oai_cn5g_oc.html',
                              selector: lastCompleted())
              }
            }
432
433
434
435
          }
        }
      }
    }
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
  }
  post {
    success {
      script {
        if ("MERGE".equals(env.gitlabActionType)) {
          def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): passed (" + BUILD_URL + ")"
          echo "This is a MERGE event"
          addGitLabMRComment comment: message
        }
      }
    }
    unsuccessful {
      script {
        if ("MERGE".equals(env.gitlabActionType)) {
          def message = "OAI " + JOB_NAME + " build (" + BUILD_ID + "): failed (" + BUILD_URL + ")"
          echo "This is a MERGE event"
          addGitLabMRComment comment: message
        }
      }
    }
    cleanup {
      script {
Mohammed Ismail's avatar
Mohammed Ismail committed
458
459
        if ("MERGE".equals(env.gitlabActionType)) {
          // Remove CI Base image tag
Mohammed Ismail's avatar
Mohammed Ismail committed
460
          myShCmd('docker rmi oai-nrf-base:latest', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
Mohammed Ismail's avatar
Mohammed Ismail committed
461
        }
462
463
464
        // Removing temporary / intermediate images
        try {
          if ("MERGE".equals(env.gitlabActionType)) {
Mohammed Ismail's avatar
Mohammed Ismail committed
465
466
467
468
469
470
471
472
            myShCmd('docker image rm --force oai-nrf:ci-tmp', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
          }
        } catch (Exception e) {
          echo "We failed to delete the OAI-NRF temp image"
        }
        try {
          if ("MERGE".equals(env.gitlabActionType)) {
            myShCmd('sudo podman image rm oai-nrf:ci-tmp', rem_rhel_host_flag, rem_rhel_host_user, rem_rhel_host)
473
474
475
476
477
          }
        } catch (Exception e) {
          echo "We failed to delete the OAI-NRF temp image"
        }
        try {
Mohammed Ismail's avatar
Mohammed Ismail committed
478
          myShCmd('docker image prune --force', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
479
480
481
        } catch (Exception e) {
          echo "We failed to prune all unneeded intermediate images"
        }
Mohammed Ismail's avatar
Mohammed Ismail committed
482
483
484
485
486
487
488
        if (rem_rhel_host_flag) {
          try {
            myShCmd('sudo podman image prune --force', rem_rhel_host_flag, rem_rhel_host_user, rem_rhel_host)
          } catch (Exception e) {
            echo "We failed to prune all unneeded intermediate images"
          }
        }
489

490
491
492
493
494
495
496
497
498
        // Zipping all archived log files
        sh "zip -r -qq docker_logs.zip archives"
        if (fileExists('docker_logs.zip')) {
          archiveArtifacts artifacts: 'docker_logs.zip'
        }

        // Generating the HTML report
        if ("MERGE".equals(env.gitlabActionType)) {
          sh "python3 ci-scripts/generateHtmlReport.py --job_name=${JOB_NAME} --job_id=${BUILD_ID} --job_url=${BUILD_URL} --git_url=${GIT_URL} --git_src_branch=${env.gitlabSourceBranch} --git_src_commit=${env.gitlabMergeRequestLastCommit} --git_pull_request=True --git_target_branch=${env.gitlabTargetBranch} --git_target_commit=${GIT_COMMIT}"
Mohammed Ismail's avatar
Mohammed Ismail committed
499
500
501
502
503
504
505
506
          if (fileExists('test_results_oai_nrf.html')) {
            sh "sed -i -e 's#TEMPLATE_MERGE_REQUEST_LINK#${gitlabMergeRequestLink}#g' test_results_oai_nrf.html"
            sh "sed -i -e 's#TEMPLATE_MERGE_REQUEST_TEMPLATE#${env.gitlabMergeRequestTitle}#' test_results_oai_nrf.html"
          }
          if (fileExists('test_results_oai_cn5g.html')) {
            sh "sed -i -e 's#TEMPLATE_MERGE_REQUEST_LINK#${gitlabMergeRequestLink}#g' *_results_oai_cn5g.html"
            sh "sed -i -e 's#TEMPLATE_MERGE_REQUEST_TEMPLATE#${env.gitlabMergeRequestTitle}#' *_results_oai_cn5g.html"
          }
ismail's avatar
ismail committed
507
508
509
510
          if (fileExists('test_results_oai_nrf_bt.html')) {
            sh "sed -i -e 's#TEMPLATE_MERGE_REQUEST_LINK#${gitlabMergeRequestLink}#g' *_results_oai_nrf_bt.html"
            sh "sed -i -e 's#TEMPLATE_MERGE_REQUEST_TEMPLATE#${env.gitlabMergeRequestTitle}#' *_results_oai_nrf_bt.html"
          }
511
512
513
514
          if (fileExists('test_results_oai_cn5g_oc.html')) {
            sh "sed -i -e 's#TEMPLATE_MERGE_REQUEST_LINK#${gitlabMergeRequestLink}#g' *_results_oai_cn5g_oc.html"
            sh "sed -i -e 's#TEMPLATE_MERGE_REQUEST_TEMPLATE#${env.gitlabMergeRequestTitle}#' *_results_oai_cn5g_oc.html"
          }
515
516
517
518
519
        } else {
          sh "python3 ci-scripts/generateHtmlReport.py --job_name=${JOB_NAME} --job_id=${BUILD_ID} --job_url=${BUILD_URL} --git_url=${GIT_URL} --git_src_branch=${GIT_BRANCH} --git_src_commit=${GIT_COMMIT}"
        }
        sh "sed -i -e 's#TEMPLATE_TIME#${JOB_TIMESTAMP}#' test_results_oai_nrf.html"
        if (fileExists('test_results_oai_nrf.html')) {
Mohammed Ismail's avatar
Mohammed Ismail committed
520
          sh "sed -i -e 's#TEMPLATE_TIME#${JOB_TIMESTAMP}#' test_results_oai_nrf.html"
521
522
          archiveArtifacts artifacts: 'test_results_oai_nrf.html'
        }
523
        if (fileExists('test_results_oai_cn5g.html')) {
524
525
526
          sh "sed -i -e 's#TEMPLATE_TIME#${JOB_TIMESTAMP}#' *_results_oai_cn5g.html"
          archiveArtifacts artifacts: '*_results_oai_cn5g.html'
        }
ismail's avatar
ismail committed
527
528
529
530
        if (fileExists('test_results_oai_nrf_bt.html')) {
          sh "sed -i -e 's#TEMPLATE_TIME#${JOB_TIMESTAMP}#' *_results_oai_nrf_bt.html"
          archiveArtifacts artifacts: '*_results_oai_nrf_bt.html'
        }
531
532
533
534
        if (fileExists('test_results_oai_cn5g_oc.html')) {
          sh "sed -i -e 's#TEMPLATE_TIME#${JOB_TIMESTAMP}#' *_results_oai_cn5g_oc.html"
          archiveArtifacts artifacts: '*_results_oai_cn5g_oc.html'
        }
535
536
537
538
539
540

        // Sending email to commiter
        if (params.sendToCommitterEmail != null) {
          if (params.sendToCommitterEmail) {
            emailext attachmentsPattern: '*results*.html',
              body: '''Hi,
541
542


543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
Here are attached HTML report files for $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!

Regards,
OAI CI Team''',
              replyTo: 'no-reply@openairinterface.org',
              subject: '$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!',
              to: gitCommitAuthorEmailAddr
          }
        }
      }
    }
  }
}

def copyTo2ndServer(filename, flag, user, host) {
  if (flag) {
    if ("openair-nrf.tar.bz2".equals(filename)) {
      sh "ssh ${user}@${host} 'rm -rf /tmp/CI-CN-NRF'"
      sh "ssh ${user}@${host} 'mkdir -p /tmp/CI-CN-NRF'"
    }
    sh "scp ${filename} ${user}@${host}:/tmp/CI-CN-NRF"
    if ("openair-nrf.tar.bz2".equals(filename)) {
      sh "ssh ${user}@${host} 'cd /tmp/CI-CN-NRF && tar -xjf ${filename}'"
      sh "ssh ${user}@${host} 'mkdir -p /tmp/CI-CN-NRF/archives/oai-nrf-cfg'"
Mohammed Ismail's avatar
Mohammed Ismail committed
567
      sh "ssh ${user}@${host} 'rm -Rf /tmp/CI-CN-NRF/${filename}'"
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
    }
  }
}

def copyFrom2ndServer(filename, target, flag, user, host) {
  if (flag) {
    sh "scp ${user}@${host}:/tmp/CI-CN-NRF/${filename} ${target}"
  }
}

def myShCmd(cmd, flag, user, host) {
  if (flag) {
    sh "ssh -t -t ${user}@${host} 'cd /tmp/CI-CN-NRF && ${cmd}'"
  } else {
    sh "${cmd}"
  }
}

def myShRetCmd(cmd, flag, user, host) {
  if (flag) {
    ret = sh returnStdout: true, script: "ssh -t -t ${user}@${host} 'cd /tmp/CI-CN-NRF && ${cmd}'"
  } else {
    ret = sh returnStdout: true, script: "${cmd}"
  }
  ret = ret.trim()
  return ret
}