Nightly: Email notification to people in the group

The email will trigger after the job finish to archive the artifacts.

Signed-off-by: Karl Zhang <karl.zhang@arm.com>
Change-Id: I0c8484343a69a9a8db092a7baa371f087fd41136
diff --git a/jenkins/ci.jpl b/jenkins/ci.jpl
index f7bdc9c..ccf4a18 100644
--- a/jenkins/ci.jpl
+++ b/jenkins/ci.jpl
@@ -95,6 +95,21 @@
   }
 }
 
+def emailNotification(results) {
+  script {
+   if (env.JOB_NAME.equals("tf-m-nightly") && !env.EMAIL_NOTIFICATION.equals('')) {
+      def result = "Fail."
+      if (results)
+        result = "Success."
+      emailext (
+          subject: ("Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} ${result}"),
+          body: "Check console output at ${env.BUILD_URL}",
+          to: "${EMAIL_NOTIFICATION}"
+      )
+    }
+  } /* script */
+}
+
 @NonCPS
 def generateCsvContent(results) {
   def resultsParam = []
@@ -337,6 +352,7 @@
       success = false
     } finally {
       archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true
+      emailNotification(success);
       cleanWs()
       if (!success) {
         error("There was an Error waiting for LAVA jobs")