From: Holger Levsen Date: Fri, 12 Oct 2012 13:24:34 +0000 (+0200) Subject: trap failed builds and mark them as such in cidb X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=47fcba5a0b56f889a3db5349f27bbd747f9ba47b;p=profitbricks%2Fjenkins-build-scripts.git trap failed builds and mark them as such in cidb --- diff --git a/db_add.py b/db_add.py index abf06f8..e498b7c 100755 --- 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 diff --git a/liveboot2db.py b/liveboot2db.py index cc5e93e..dc9a259 100755 --- a/liveboot2db.py +++ b/liveboot2db.py @@ -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) diff --git a/liveboot_build.sh b/liveboot_build.sh index ba5f47c..a9b0bc8 100755 --- a/liveboot_build.sh +++ b/liveboot_build.sh @@ -3,6 +3,12 @@ # copyright 2012 Holger Levsen # 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