[CORD-2966]v2 - fix issues with the first patch of helm-api-test

Change-Id: I4cb8d4fb0e4eeb33b2b455731370e8333c9a4fad
diff --git a/jjb/helm-api-test.yaml b/jjb/helm-api-test.yaml
index a9ec6a8..1e32c00 100644
--- a/jjb/helm-api-test.yaml
+++ b/jjb/helm-api-test.yaml
@@ -41,6 +41,21 @@
          default: '$GERRIT_BRANCH'
          description: 'Name of the repo branch to use'
 
+      - string:
+         name: gerritProject
+         default: '$GERRIT_PROJECT'
+         description: 'Name of the Gerrit project'
+
+      - string:
+         name: gerritChangeNumber
+         default: '$GERRIT_CHANGE_NUMBER'
+         description: 'Changeset number in Gerrit'
+
+      - string:
+         name: gerritPatchsetNumber
+         default: '$GERRIT_PATCHSET_NUMBER'
+         description: 'PatchSet number in Gerrit'
+
     project-type: pipeline
     concurrent: true
 
diff --git a/jjb/pipeline/helm-api-test.groovy b/jjb/pipeline/helm-api-test.groovy
index c776510..adedd8c 100644
--- a/jjb/pipeline/helm-api-test.groovy
+++ b/jjb/pipeline/helm-api-test.groovy
@@ -2,26 +2,20 @@
 
 pipeline {
 
-  parameters {
-    string(name:'executorNode', defaultValue:'invalid', description:'Name of the Jenkins node to run the job on')
-    string(name:'manifestUrl', defaultValue:'invalid', description:'URL to the repo manifest')
-    string(name:'manifestBranch', defaultValue:'master', description:'Name of the repo branch to use')
-  }
-
   /* no label, executor is determined by JJB */
   agent {
-    label '${params.executorNode}'
+    label "${params.executorNode}"
   }
 
   stages {
 
-    stage('checkout') {
+    stage('repo') {
       steps {
         checkout(changelog: false, \
           poll: false,
           scm: [$class: 'RepoScm', \
-            manifestRepositoryUrl: '${params.manifestUrl}', \
-            manifestBranch: '${params.manifestBranch}', \
+            manifestRepositoryUrl: "${params.manifestUrl}", \
+            manifestBranch: "${params.manifestBranch}", \
             currentBranch: true, \
             destinationDir: 'cord', \
             forceSync: true,
@@ -33,13 +27,27 @@
       }
     }
 
+    stage('patch') {
+      steps {
+        sh """
+           pushd cord
+           PROJECT_PATH=$(xmllint --xpath "string(//project[@name=\"${gerritProject}\"]/@path)" .repo/manifest.xml)
+           repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}"
+           popd
+           """
+      }
+    }
+
     stage('prep') {
       parallel {
 
         stage('images') {
           steps {
-            sh 'cd cord/build; ./scripts/imagebuilder.py -f helm-charts/examples/test-images.yaml'
-
+            sh '''
+               pushd cord/build
+               ./scripts/imagebuilder.py -f ../helm-charts/examples/test-images.yaml
+               popd
+               '''
           }
         }
 
@@ -47,17 +55,14 @@
           steps {
             /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */
             sh '''
-               export MINIKUBE_WANTUPDATENOTIFICATION=false;
-               export MINIKUBE_WANTREPORTERRORPROMPT=false;
-               export CHANGE_MINIKUBE_NONE_USER=true;
-               export MINIKUBE_HOME=$HOME;
-               mkdir -p $HOME/.kube || true;
-               touch $HOME/.kube/config;
-               export KUBECONFIG=$HOME/.kube/config;
-               minikube start --vm-driver=none;
-
-               chown -R $USER $HOME/.minikube;
-               chgrp -R $(id -g) $HOME/.minikube;
+               export MINIKUBE_WANTUPDATENOTIFICATION=false
+               export MINIKUBE_WANTREPORTERRORPROMPT=false
+               export CHANGE_MINIKUBE_NONE_USER=true
+               export MINIKUBE_HOME=$HOME
+               mkdir -p $HOME/.kube || true
+               touch $HOME/.kube/config
+               export KUBECONFIG=$HOME/.kube/config
+               sudo -E /usr/bin/minikube start --vm-driver=none
 
                for i in {1..150}; do # timeout for 5 minutes
                    ./kubectl get po &> /dev/null
@@ -81,32 +86,43 @@
     stage('xos') {
       steps {
         sh '''
-           cd cord/build/helm-charts;
-           helm dep up xos-core;
-           helm install -f examples/test-values.yaml -f examples/candidate-tag-values.yaml xos-core -n xos-core;
+           pushd cord/helm-charts
+           helm dep up xos-core
+           helm install -f examples/test-values.yaml -f examples/candidate-tag-values.yaml xos-core -n xos-core
            sleep 60
+           popd
            '''
       }
     }
 
     stage('test'){
       steps {
-        sh 'helm test xos-core'
-        sh 'kubectl logs xos-core-api-test'
-      }
-      post {
-        always {
-          archive '/tmp/helm_test_xos_core_logs_*/**'
+        sh '''
+           helm test xos-core
+           kubectl logs xos-core-api-test
+           mkdir -p ./RobotLogs;
+           cp /tmp/helm_test_xos_core_logs_*/* ./RobotLogs
+           '''
 
-        }
+        step([$class: 'RobotPublisher',
+             disableArchiveOutput: false,
+             logFileName: 'RobotLogs/log*.html',
+             otherFiles: '',
+             outputFileName: 'RobotLogs/output*.xml',
+             outputPath: '.',
+             passThreshold: 100,
+             reportFileName: 'RobotLogs/report*.html',
+             unstableThreshold: 0]);
       }
     }
   }
 
   post {
     always {
-      sh 'kubectl delete pod xos-core-api-test'
-      sh 'helm delete --purge xos-core'
+      sh '''
+         kubectl delete pod xos-core-api-test
+         helm delete --purge xos-core
+         '''
       deleteDir()
     }
   }