Distinguish build and test result

Only send email when got fail.

Change-Id: I8ef7ae8da40d87698df482b376105c1bc6c8a0fc
Signed-off-by: Karl Zhang <karl.zhang@arm.com>
Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
diff --git a/jenkins/ci.jpl b/jenkins/ci.jpl
index 7f36282..3504d1b 100644
--- a/jenkins/ci.jpl
+++ b/jenkins/ci.jpl
@@ -254,17 +254,21 @@
   }
 }
 
-def emailNotification(results) {
+def emailNotification(results, stage) {
   script {
    if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
       def result = "Fail."
-      if (results)
+      if (results == true) {
         result = "Success."
-      emailext (
-          subject: ("Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} ${result}"),
-          body: "Check console output at ${env.BUILD_URL}",
-          to: "${EMAIL_NOTIFICATION}"
-      )
+        print("Skip sending as ${result} for ${stage}")
+      }
+      else {
+        emailext (
+            subject: ("Job ${env.JOB_NAME} ${stage} ${env.BUILD_NUMBER} ${result}"),
+            body: "Check console output at ${env.BUILD_URL}",
+            to: "${EMAIL_NOTIFICATION}"
+        )
+      }
     }
   } /* script */
 }
@@ -446,14 +450,17 @@
 
 stage("Builds") {
   def verify = 1
+  def success = true
   try {
     parallel(builds)
   } catch (Exception e) {
     print(e)
     manager.buildFailure()
     verify = -1
+    success = false
   } finally {
     print("Verifying status")
+    emailNotification(success, 'Build')
     g = new Gerrit()
     g.verifyStatus(verify, 'tf-m-build', 'build')
     print("Building CSV")
@@ -516,7 +523,7 @@
       success = false
     } finally {
       archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
-      emailNotification(success);
+      emailNotification(success, 'Test')
       cleanWs()
       if (!success) {
         error("There was an Error waiting for LAVA jobs")