Fix bug 1563 to archive logs even if OSM Health stage fails 51/10851/9
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 30 Mar 2022 14:52:59 +0000 (16:52 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 30 Mar 2022 14:53:21 +0000 (16:53 +0200)
Change-Id: I1ed08f0220673b2d5ef69291d67821060e6ad2ac
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
jenkins/ci-pipelines/ci_stage_3.groovy

index 2fb7434..8ef3031 100644 (file)
@@ -176,6 +176,7 @@ node("${params.NODE}") {
     INTERNAL_DOCKER_PROXY = 'http://172.21.1.1:5000'
     APT_PROXY = 'http://172.21.1.1:3142'
     SSH_KEY = '~/hive/cicd_rsa'
+    ARCHIVE_LOGS_FLAG = false
     sh 'env'
 
     tag_or_branch = params.GERRIT_BRANCH.replaceAll(/\./, '')
@@ -547,6 +548,8 @@ node("${params.NODE}") {
 // Health check of installed OSM in remote vm
 ///////////////////////////////////////////////////////////////////////////////////////
                 stage('OSM Health') {
+                    // if this point is reached, logs should be archived
+                    ARCHIVE_LOGS_FLAG = true
                     stackName = 'osm'
                     sshCommand remote: remote, command: """
                         /usr/share/osm-devops/installers/osm_health.sh -k -s ${stackName}
@@ -596,9 +599,7 @@ EOF"""
                         )
                     } // stage("System Integration Test")
                 } finally {
-                    stage('Archive Container Logs') {
-                        // Archive logs to containers_logs.txt
-                        archive_logs(remote)
+                    stage('After System Integration test') {
                         if (currentBuild.result != 'FAILURE') {
                             stage_archive = keep_artifacts
                         } else {
@@ -673,34 +674,52 @@ EOF"""
             } // if (params.SAVE_ARTIFACTS_OVERRIDE || stage_archive)
         } // dir(OSM_DEVOPS)
     } finally {
-        if ( params.DO_INSTALL && server_id != null) {
-            delete_vm = true
-            if (error && params.SAVE_CONTAINER_ON_FAIL ) {
-                delete_vm = false
-            }
-            if (!error && params.SAVE_CONTAINER_ON_PASS ) {
-                delete_vm = false
-            }
+       stage('Archive Container Logs') {
+            if ( ARCHIVE_LOGS_FLAG ) {
+                // Archive logs
+                remote = [
+                    name: containerName,
+                    host: IP_ADDRESS,
+                    user: 'ubuntu',
+                    identityFile: SSH_KEY,
+                    allowAnyHosts: true,
+                    logLevel: 'INFO',
+                    pty: true
+                ]
+                println('Archiving container logs')
+                archive_logs(remote)
+            } // end if ( ARCHIVE_LOGS_FLAG )
+        }
+        stage('Cleanup') {
+            if ( params.DO_INSTALL && server_id != null) {
+                delete_vm = true
+                if (error && params.SAVE_CONTAINER_ON_FAIL ) {
+                    delete_vm = false
+                }
+                if (!error && params.SAVE_CONTAINER_ON_PASS ) {
+                    delete_vm = false
+                }
 
-            if ( delete_vm ) {
-                if (server_id != null) {
-                    println("Deleting VM: $server_id")
-                    sh """#!/bin/sh -e
-                        for line in `grep OS ~/hive/robot-systest.cfg | grep -v OS_CLOUD` ; do export \$line ; done
-                        openstack server delete ${server_id}
-                    """
-                } else {
-                    println("Saved VM $server_id in ETSI VIM")
+                if ( delete_vm ) {
+                    if (server_id != null) {
+                        println("Deleting VM: $server_id")
+                        sh """#!/bin/sh -e
+                            for line in `grep OS ~/hive/robot-systest.cfg | grep -v OS_CLOUD` ; do export \$line ; done
+                            openstack server delete ${server_id}
+                        """
+                    } else {
+                        println("Saved VM $server_id in ETSI VIM")
+                    }
                 }
             }
-        }
-        if ( http_server_name != null ) {
-            sh "docker stop ${http_server_name} || true"
-            sh "docker rm ${http_server_name} || true"
-        }
+            if ( http_server_name != null ) {
+                sh "docker stop ${http_server_name} || true"
+                sh "docker rm ${http_server_name} || true"
+            }
 
-        if ( devopstempdir != null ) {
-            sh "rm -rf ${devopstempdir}"
+            if ( devopstempdir != null ) {
+                sh "rm -rf ${devopstempdir}"
+            }
         }
     }
 }