Jenkins script for nightly jobs

Change-Id: I1b326b8eb8ccf5cb34fabd14ba622869540b6ce4
diff --git a/Jenkinsfile-rcordlite b/Jenkinsfile-rcordlite
index 9708015..26fd666 100644
--- a/Jenkinsfile-rcordlite
+++ b/Jenkinsfile-rcordlite
@@ -20,113 +20,126 @@
             sh returnStdout: true, script: 'rm -rf ${configRepoBaseDir}'
             sh returnStdout: true, script: 'git clone -b ${branch} ${configRepoUrl}'
             deployment_config = readYaml file: "${configRepoBaseDir}${configRepoFile}"
-            pod_config = readYaml file: "${configRepoBaseDir}${deployment_config.pod_config.file_name}"
         }
-
-    stage('Clean up') {
-        timeout(10) {
-            try {
-                sh """
-                helm delete --purge onos-voltha
-                helm delete --purge onos-fabric
-                helm delete --purge voltha
-                helm delete --purge rcord-lite
-                helm delete --purge xos-core
-                """
-            } catch(error) { currentBuild.result = 'FAILURE' }
-    }
-    stage('Export pod config') {
-        timeout(10) {
-            try {
-                sh """
-                export KUBECONFIG=/home/cord/${pod_config.pod_config}
-                """
-            } catch(error) { currentBuild.result = 'FAILURE' }
-    }
-    stage('Install xos-core and rcord-lite') {
-        timeout(10) {
-            try {
-                sh """
-                rm -rf ~/helm-charts*
-                git clone -b ${branch} https://gerrit.opencord.org/helm-charts
-                cd helm-charts
-                helm dep update xos-core
-                helm install -n xos-core xos-core
-                helm dep update xos-profiles/rcord-lite
-                helm install -n rcord-lite xos-profiles/rcord-lite
-                """
-            } catch(error) { currentBuild.result = 'FAILURE' }
+        
+        stage('Export pod config') {
+            timeout(10) {
+                try {
+                    sh """
+                    cd /home/cord
+                    rm -rf /home/cord/helm-charts
+                    git clone -b ${branch} https://gerrit.opencord.org/helm-charts
+                    export KUBECONFIG=/home/cord/${deployment_config.pod_config}
+                    kubectl get pods
+                    """
+                } catch(error) { currentBuild.result = 'FAILURE' }
+            }
         }
-    }
-    stage('Install voltha') {
-        timeout(10) 
+        stage('Clean up') {
+            timeout(10) {
+                try {
+                    sh """
+                    cd /home/cord/helm-charts
+                    export KUBECONFIG=/home/cord/${deployment_config.pod_config}
+                    helm ls | grep onos-voltha && helm delete --purge onos-voltha
+                    helm ls | grep onos-fabric && helm delete --purge onos-fabric
+                    helm ls | grep voltha && helm delete --purge voltha
+                    helm ls | grep rcord-lite && helm delete --purge rcord-lite
+                    helm ls | grep xos-core && helm delete --purge xos-core
+                    sleep 120
+                    """
+                } catch(error) { currentBuild.result = 'FAILURE' }
+            }    
+        }
+        stage('Install xos-core and rcord-lite') {
+            timeout(10) {
+                try {
+                    sh """
+                    export KUBECONFIG=/home/cord/${deployment_config.pod_config}
+                    cd /home/cord/helm-charts
+                    helm dep update xos-core
+                    helm install -n xos-core xos-core
+                    helm dep update xos-profiles/rcord-lite
+                    helm install -n rcord-lite xos-profiles/rcord-lite
+                    """
+                } catch(error) { currentBuild.result = 'FAILURE' }
+            }
+        }
+        stage('Install voltha') {
+            timeout(10) {
+                try {
+                    sh """
+                    export KUBECONFIG=/home/cord/${deployment_config.pod_config}
+                    cd /home/cord/helm-charts/voltha  
+                    helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
+                    helm dep build
+                    cd /home/cord/helm-charts
+                    helm install -n voltha --set etcd-operator.customResources.createEtcdClusterCRD=false voltha
+                    helm upgrade --set etcd-operator.customResources.createEtcdClusterCRD=true voltha ./voltha
+                    """
+                } catch(error) { currentBuild.result = 'FAILURE' }
+            }
+        }
+        stage('Install ONOS-Voltha and ONOS-Fabric') {
+            timeout(10) {
+                try {
+                    sh """
+                    export KUBECONFIG=/home/cord/${deployment_config.pod_config}
+                    cd /home/cord/helm-charts
+                    helm install -n onos-fabric -f configs/onos-fabric.yaml onos
+                    helm install -n onos-voltha -f configs/onos-voltha.yaml onos
+                    """
+                } catch(error) { currentBuild.result = 'FAILURE' }
+            }
+        }
+        stage('Download cord-tester repo') {
+            timeout(10) {
+                try {
+                    sh """
+                    rm -rf /home/cord/cord-tester
+                    cd /home/cord/
+                    git clone -b ${branch} https://gerrit.opencord.org/cord-tester 
+                    """
+                } catch(error) { currentBuild.result = 'FAILURE' }
+            }
+        }
+        stage('Verify E2E XOS') {
+            timeout(10) {
+                try {
+                    sh """
+                    export KUBECONFIG=/home/cord/${deployment_config.pod_config}
+                    cd /home/cord/cord-tester/src/test/cord-api/Properties/
+                    sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'${deployment_config.node1.ip}\'/\" RestApiProperties.py
+                    sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'30006\'/\" RestApiProperties.py
+                    sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
+                    sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
+                    cd /home/cord/cord-tester/src/test/cord-api/Tests
+                    rm -rf Log/ || true
+                    pybot -d Log -T VOLTDevice_Test.txt || all_passed=false
+                    pybot -d Log -T RCORDLite_E2ETest.txt || all_passed=false
+                    if [ "\\\$all_passed" = true ]; then exit 0; else exit 1; fi
+                    """
+                } catch(error) { currentBuild.result = 'FAILURE' }
+            }
+        }
+        stage('Publish') {
             try {
                 sh """
-                cd ~/helm-charts/voltha  
-                helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
-                helm dep build
-                cd ~/helm-charts
-                helm install -n voltha --set etcd-operator.customResources.createEtcdClusterCRD=false voltha
-                helm upgrade --set etcd-operator.customResources.createEtcdClusterCRD=true voltha ./voltha
+                if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs;
+                mkdir RobotLogs/TestDoc || true
+                cp -r /home/cord/cord-tester/src/test/cord-api/Tests/Log/* ./RobotLogs || true
                 """
-            } catch(error) { currentBuild.result = 'FAILURE' }
+                step([$class: 'RobotPublisher',
+                    disableArchiveOutput: false,
+                    logFileName: 'RobotLogs/log*.html',
+                    otherFiles: '',
+                    outputFileName: 'RobotLogs/output*.xml',
+                    outputPath: '.',
+                    passThreshold: 100,
+                    reportFileName: 'RobotLogs/report*.html',
+                    unstableThreshold: 0])
+            } catch(error) {}
         }
+        step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
     }
-    stage('Install ONOS-Voltha and ONOS-Fabric') {
-        timeout(10) 
-            try {
-                sh """
-                cd ~/helm-charts
-                helm install -n onos-fabric -f configs/onos-fabric.yaml onos
-                helm install -n onos-voltha -f configs/onos-voltha.yaml onos
-                """
-            } catch(error) { currentBuild.result = 'FAILURE' }
-        }
-    }
-    stage('Download cord-tester repo') {
-        timeout(10) 
-            try {
-                sh """
-                cd ~/home/cord
-                rm -rf ~/cord-tester
-                git clone -b ${branch} https://gerrit.opencord.org/cord-tester 
-                """
-            } catch(error) { currentBuild.result = 'FAILURE' }
-        }
-    }
-   stage('Verify E2E XOS') {
-        timeout(10) {
-            try {
-                sh """
-                cd /home/cord/cord-tester/src/test/cord-api/Properties/
-                sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
-                sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
-                cd /home/cord/cord-tester/src/test/cord-api/Tests
-                rm -r Log/ || true
-                pybot -d Log -T VOLTDevice_Test.txt || all_passed=false
-                pybot -d Log -T RCORDLite_E2ETest.txt || all_passed=false
-                python -m robot.testdoc Tests/*.txt TestDoc/XOSApiTests.html
-                if [ "\\\$all_passed" = true ]; then exit 0; else exit 1; fi
-                """
-            } catch(error) { currentBuild.result = 'FAILURE' }
-        }
-    }
-    stage('Publish') {
-        try {
-            sh """
-            if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
-            scp -r sdn@{TestNodeName}:/home/cord/cord-tester/src/test/cord-api/Tests/Log/* ./RobotLogs || true
-            """
-            step([$class: 'RobotPublisher',
-                disableArchiveOutput: false,
-                logFileName: 'RobotLogs/log*.html',
-                otherFiles: '',
-                outputFileName: 'RobotLogs/output*.xml',
-                outputPath: '.',
-                passThreshold: 100,
-                reportFileName: 'RobotLogs/report*.html',
-                unstableThreshold: 0])
-        } catch(error) {}
-    }
-    step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
 }