[VOL-3780] Correctly collecting logs in openonu-go test

Change-Id: I2f471d0815855dd3cae0aea8a7969dbdb288b44a
diff --git a/jjb/pipeline/voltha/master/openonu-go-periodic-test-bbsim.groovy b/jjb/pipeline/voltha/master/openonu-go-periodic-test-bbsim.groovy
index 1010e80..0001fac 100644
--- a/jjb/pipeline/voltha/master/openonu-go-periodic-test-bbsim.groovy
+++ b/jjb/pipeline/voltha/master/openonu-go-periodic-test-bbsim.groovy
@@ -38,16 +38,6 @@
         ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9
         '''
       }
-      // stop logging
-      sh """
-        P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${workflow}" | grep -v grep | awk '{print \$1}')"
-        if [ -n "\$P_IDS" ]; then
-          echo \$P_IDS
-          for P_ID in \$P_IDS; do
-            kill -9 \$P_ID
-          done
-        fi
-      """
     }
   }
   stage('Deploy Voltha') {
@@ -98,9 +88,42 @@
 
     make -C $WORKSPACE/voltha-system-tests ${testTarget} || true
     """
+    // stop logging
+    sh """
+      P_IDS="\$(ps e -ww -A | grep "_TAG=kail-${workflow}" | grep -v grep | awk '{print \$1}')"
+      if [ -n "\$P_IDS" ]; then
+        echo \$P_IDS
+        for P_ID in \$P_IDS; do
+          kill -9 \$P_ID
+        done
+      fi
+    """
   }
 }
 
+def collectArtifacts(exitStatus) {
+  getPodsInfo("$WORKSPACE/${exitStatus}")
+  sh """
+  kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
+  """
+  archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html'
+  sh '''
+    sync
+    pkill kail || true
+    which voltctl
+    md5sum $(which voltctl)
+  '''
+  step([$class: 'RobotPublisher',
+    disableArchiveOutput: false,
+    logFileName: "RobotLogs/*/log*.html",
+    otherFiles: '',
+    outputFileName: "RobotLogs/*/output*.xml",
+    outputPath: '.',
+    passThreshold: 100,
+    reportFileName: "RobotLogs/*/report*.html",
+    unstableThreshold: 0]);
+}
+
 pipeline {
 
   /* no label, executor is determined by JJB */
@@ -165,7 +188,7 @@
       steps {
         script {
           def mibUploadHelmFlags = "--set pon=2,onu=2,controlledActivation=only-onu "
-          execute_test("1t8gem", "att", "mib-upload-templating-openonu-go-adapter-test", "$WORKSPACE/mibupload", mibUploadHelmFlags)
+          execute_test("mibupload", "att", "mib-upload-templating-openonu-go-adapter-test", "$WORKSPACE/mibupload", mibUploadHelmFlags)
         }
       }
     }
@@ -196,36 +219,13 @@
   }
   post {
     aborted {
-      getPodsInfo("$WORKSPACE/failed")
-      sh """
-      kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.log
-      """
-      archiveArtifacts artifacts: '**/*.log,**/*.txt,**/*.html'
+      collectArtifacts("aborted")
     }
     failure {
-      getPodsInfo("$WORKSPACE/failed")
-      sh """
-      kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/failed/voltha.log
-      """
-      archiveArtifacts artifacts: '**/*.log,**/*.txt,**/*.html'
+      collectArtifacts("failed")
     }
     always {
-      step([$class: 'RobotPublisher',
-        disableArchiveOutput: false,
-        logFileName: "RobotLogs/*/log*.html",
-        otherFiles: '',
-        outputFileName: "RobotLogs/*/output*.xml",
-        outputPath: '.',
-        passThreshold: 100,
-        reportFileName: "RobotLogs/*/report*.html",
-        unstableThreshold: 0]);
-      archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html'
-      sh '''
-        sync
-        pkill kail || true
-        which voltctl
-        md5sum $(which voltctl)
-      '''
+      collectArtifacts("always")
     }
   }
 }