Add Funtion : Notify the Build status of SR 23/162423/2
authorYonghee Han <onstudy@samsung.com>
Fri, 1 Dec 2017 03:20:09 +0000 (12:20 +0900)
committerYonghee Han <onstudy@samsung.com>
Mon, 4 Dec 2017 07:11:59 +0000 (16:11 +0900)
Notify status of Build and Images

Change-Id: I83929d5ccb319786c491ab2fc6571fb11ae20be7

debian/jenkins-scripts.install
job_notify_buildstatus.py [new file with mode: 0644]
job_post_image.py
job_pre_release_obs.py
packaging/jenkins-scripts.spec

index 396e7eb..a4bb3ec 100644 (file)
@@ -46,3 +46,4 @@ debian/tmp/job_gbsfullbuild_image_creator.py /var/lib/jenkins/jenkins-scripts/
 debian/tmp/job_gbsfullbuild_buildlogs.py /var/lib/jenkins/jenkins-scripts/
 debian/tmp/job_obs_worker_auto_scailing.py /var/lib/jenkins/jenkins-scripts/
 debian/tmp/job_config_snapshot_repo_conf.py /var/lib/jenkins/jenkins-scripts/
+debian/tmp/job_notify_buildstatus.py /var/lib/jenkins/jenkins-scripts/
diff --git a/job_notify_buildstatus.py b/job_notify_buildstatus.py
new file mode 100644 (file)
index 0000000..9d87919
--- /dev/null
@@ -0,0 +1,92 @@
+import os
+import sys
+import base64
+import xml.etree.cElementTree as ElementTree
+from common.buildtrigger import trigger_info
+from common.send_mail import prepare_mail
+
+def send_mail_buildstatus(info):
+    """ send mail about buildstatus """
+    EMAIL_TITLE = "SR[%s] %s %s"
+    EMAIL_BODY = "The status of SR has been updated.\n" \
+                 "Please check the following details.\n\n" \
+                 "SR tag: %s\n" \
+                 "Packages : %s\n\n" \
+                 "Result\n" \
+                 "Build : %s\n" \
+                 "Image : %s\n" \
+                 "For more details, please refer to %s"
+
+    EMAIL_FOOTER = '\n\n--------------------------------------------------------\n'\
+                   'Automatically generated by backend service.\n'\
+                   'Please DO NOT Reply!'
+    imgsuccess, imgfailed, imgstatus = 0, 0, ''
+    buildsuccess, buildfailed, buildstatus = 0, 0, ''
+    submitters = info.get('submitter')
+
+    if info.get('buildstatus'):
+        for status in info.get("buildstatus"):
+            buildstatus += "\n %s arch: %s (%s:%s)" \
+                           % (status.get('repo'),status.get('arch'), \
+                              status.get('code'),status.get('count') \
+                             )
+            if status.get('code') != 'succeeded':
+                buildfailed += 1
+            else:
+                buildsuccess += 1
+
+        buildstatus += '\n'
+
+        if buildfailed > 0:
+            title_build = 'Build(Failed)'
+        else:
+            title_build = 'Build(Succeeded)'
+    else:
+        title_build=None
+        buildstatus=None
+
+    if info.get('images'):
+        for image in info.get('images'):
+            if image['status'] == 'success':
+                imgsuccess += 1
+            if image['status'] == 'failed':
+                imgfailed += 1
+
+        if imgfailed > 0:
+            title_image = 'Image(Failed)'
+        else:
+            title_image = 'Image(Succeeded)'
+        imgstatus += "\n success (%s)  failed (%s) \n" % (imgsuccess, imgfailed)
+    else:
+        title_image=None
+        imgstatus=None
+   
+    dashboard_url = os.path.join(os.getenv('DASHBOARD_URL'), "index.code?sr=" + info.get('git_tag'))
+
+    #make a message
+    title = EMAIL_TITLE % (info.get('git_tag'), title_build, title_image)
+    email_body = EMAIL_BODY % ( info.get('git_tag'), info.get('packages'), buildstatus, imgstatus, dashboard_url)
+    msg = 'Hello \n\n' + email_body + EMAIL_FOOTER
+    print submitters
+    print title
+    print msg
+    if submitters:
+        prepare_mail("%s.env" % os.getenv('BUILD_TAG'), title, msg,
+                     os.getenv('NOREPLY_EMAIL_SENDER'), submitters)
+
+def main():
+    """The main body"""
+
+    saved_info = trigger_info(os.getenv('TRIGGER_INFO'))
+
+    project = saved_info.get('obs_url').split('project=')[-1]
+    if project is None:
+        raise LocalError('Please check the project (%s)' \
+                         % (project))
+
+    send_mail_buildstatus(saved_info)
+
+if __name__ == '__main__':
+    sys.exit(main())
+
index a11acf6..17881b1 100755 (executable)
@@ -124,6 +124,9 @@ def main():
                 else:
                     print 'skip_test_trigger!!\n'
 
+                # NOTIFY BUILDSTATUS
+                trigger_next("NOTIFY-BUILDSTATUS", checkinfo)
+
                 if buildmonitor_enabled:
                     #buildmonitor.end_create_image_for_sr_stage(bm_start_datetime,
                     #                                           project)
index 25fff70..3f9bbcc 100755 (executable)
@@ -624,6 +624,11 @@ def main(action):
                 parm_backend['BACKEND_SELECTION'] = 'BACKEND_%02d' % bknd
                 break
         trigger_next("post-snapshot", data, extra_params=parm_backend)
+
+        if bBuildFail == True:
+            # NOTIFY BUILDSTATUS
+            trigger_next("NOTIFY-BUILDSTATUS", info)
+
     elif action == 'cleanup':
         # request(SR) end of life, this founction should be called to
         # delete the prerelease project "
index 393aec0..5d24c74 100644 (file)
@@ -180,6 +180,7 @@ fi
 %{destdir}/job_gbsfullbuild_buildlogs.py
 %{destdir}/job_obs_worker_auto_scailing.py
 %{destdir}/job_config_snapshot_repo_conf.py
+%{destdir}/job_notify_buildstatus.py
 
 %files common
 %defattr(-,jenkins,jenkins)