]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
trap failed builds and mark them as such in cidb
authorHolger Levsen <holger@layer-acht.org>
Fri, 12 Oct 2012 13:24:34 +0000 (15:24 +0200)
committerHolger Levsen <holger@layer-acht.org>
Fri, 12 Oct 2012 13:24:34 +0000 (15:24 +0200)
db_add.py
liveboot2db.py
liveboot_build.sh

index abf06f85452ef076f4288c7b4a69546206ae1a2a..e498b7c5b79335cefdd489fa4971f214ebd25ee3 100755 (executable)
--- a/db_add.py
+++ b/db_add.py
@@ -177,9 +177,9 @@ def add_liveboot_build(job_name, build_number, request_id, start):
     logger.info("CIDB init for liveboot OK.")
     return
 
-def finish_liveboot_build(build_id, end):
+def finish_liveboot_build(build_id, end, status):
     con = db_connect()
-    db_update_build(con, build_id, end, 'successful')
+    db_update_build(con, build_id, end, status)
     con.commit()
     logger.info("CIDB update for liveboot OK.")
     return
index cc5e93ecd309171c346e5e881b736aca56ef4640..dc9a25906f8905dde47d808e8be6c7dff37216cd 100755 (executable)
@@ -7,12 +7,12 @@ from db_add import *
 
 
 if __name__ == '__main__':
-    if len(sys.argv) != 5 and len(sys.argv) !=6:
+    if len(sys.argv) != 5 and len(sys.argv) !=7:
         # if the build was just started:
         print("usage: %s $job_name $build_number $liveboot_request_id $start_time")
         print("or:")
         # if the build was successful
-        print("usage: %s $job_name $build_number $liveboot_request_id $start_time $end_time")
+        print("usage: %s $job_name $build_number $liveboot_request_id $start_time $end_time $status")
         sys.exit(1)
 
     job_name = sys.argv[1]
@@ -20,11 +20,12 @@ if __name__ == '__main__':
     request_id = sys.argv[3]
     start = sys.argv[4]
 
-    if len(sys.argv) != 6:
+    if len(sys.argv) != 7:
         add_liveboot_build(job_name, build_number, request_id, start)
     else:
         end = sys.argv[5]
+        status = sys.argv[6]
         build_id = get_liveboot_build_id(job_name, build_number)
-        finish_liveboot_build(build_id, end)
+        finish_liveboot_build(build_id, end, status)
 
 
index ba5f47cc45b8c9edd4aae40edf9499ea090e9bde..a9b0bc83bae73f435fb3f955e956c1159a6c50c6 100755 (executable)
@@ -3,6 +3,12 @@
 # copyright 2012 Holger Levsen <holger@layer-acht.org>
 # GPL2 licenced
 
+set_failure() {
+       BUILD_END=$(date +%s)
+       $SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER $REQUEST_ID $BUILD_START $BUILD_END "failed"
+        exit 1
+}
+
 set -e
 #set -x
 export
@@ -49,6 +55,11 @@ EOF
 BUILD_START=$(date +%s)
 $SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER $REQUEST_ID $BUILD_START
 
+#
+# trap failures
+#
+trap set_failure INT TERM EXIT
+
 #
 # build liveboot
 #
@@ -59,7 +70,7 @@ rm $BUILD_SCRIPT
 # add liveboot build result to cidb
 #
 BUILD_END=$(date +%s)
-$SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER $REQUEST_ID $BUILD_START $BUILD_END
+$SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER $REQUEST_ID $BUILD_START $BUILD_END "successful"
 
 # FIXME: too much sudo here...
 cd /srv/build/liveboot/builds
@@ -106,3 +117,8 @@ figlet "mirror to DC1+2 OK"
 
 du -sh /srv/mirror/liveboot
 figlet "OK"
+
+#
+# remove trap to not set failure at the end :)
+#
+trap - INT TERM EXIT