]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
also update liveboot_request_jenkins_build after successful build
authorHolger Levsen <holger@layer-acht.org>
Thu, 11 Oct 2012 14:52:20 +0000 (16:52 +0200)
committerHolger Levsen <holger@layer-acht.org>
Thu, 11 Oct 2012 14:52:20 +0000 (16:52 +0200)
db_add.py
liveboot2db.py
liveboot_build.sh

index 26ce25de157703f02534d03f5fe0e46c6e4d0a95..24e209f65a138d90987c2172155b55b7fb2e111a 100755 (executable)
--- a/db_add.py
+++ b/db_add.py
@@ -129,6 +129,16 @@ def add_package_version(origin, package, version):
     con.commit()
     return db_package_instance_id
 
+def db_add_requested_liveboot_build (con, request_id, build_id)
+    cur = con.cursor()
+    cur.execute("SAVEPOINT a")
+    try:
+        cur.execute("INSERT INTO liveboot_request_jenkins_build(liveboot_request_id, jenkins_build_id) VALUES(%s, %s) RETURNING id" % (request_id_ build_id))
+    except psycopg2.DatabaseError as e:
+        cur.execute("ROLLBACK TO a")  # have to rollback after failed command
+        #logger.debug("INSERT INTO jenkins_build(jenkins_build_number, jenkins_job_id) VALUES(%s, %s) RETURNING id" % (number, db_id))
+    return cur.fetchone()[0]
+
 def get_package_instance(origin, package, version):
     con = db_connect()
     cur = con.cursor()
@@ -160,18 +170,19 @@ def get_liveboot_build_id(job_name, build_number):
         return False
     return cur.fetchone()[0]
 
-def add_liveboot_build(job_name, build_number):
+def add_liveboot_build(job_name, build_number, request_id):
     con = db_connect()
     db_job_id = db_add_job(con, job_name)
     db_build_id = db_add_build (con, build_number, db_job_id)
+    db_add_requested_liveboot_build (con, request_id, build_id)
     con.commit()
     logger.info("CIDB init for liveboot OK.")
-    return db_build_id
+    return
 
 def finish_liveboot_build(build_id, start, end):
     con = db_connect()
-    db_build_result_id = db_add_build_result (con, build_id, start, end, 'true')
+    db_add_build_result (con, build_id, start, end, 'true')
     con.commit()
     logger.info("CIDB update for liveboot OK.")
-    return db_build_result_id
+    return
 
index ee3d3932708b201d1c7b68e6dfae6b1c71fbd53f..107e45d0d34af3adaa36cb6d353dda848f3b1f37 100755 (executable)
@@ -7,18 +7,23 @@ from db_add import *
 
 
 if __name__ == '__main__':
-    if len(sys.argv) != 3 and len(sys.argv) !=5:
-        print("usage: %s $packages_file $origin")
+    if len(sys.argv) != 4 and len(sys.argv) !=6:
+        # if the build was just started:
+        print("usage: %s $job_name $build_number $liveboot_request_id")
+        print("or:")
+        # if the build was successful
+        print("usage: %s $job_name $build_number $liveboot_request_id $start_time $end_time")
         sys.exit(1)
 
     job_name = sys.argv[1]
     build_number = sys.argv[2]
+    request_id = sys.argv[3]
 
-    if len(sys.argv) != 5:
-        add_liveboot_build(job_name, build_number)
+    if len(sys.argv) != 6:
+        add_liveboot_build(job_name, build_number, request_id)
     else:
-        begin = sys.argv[3]
-        end = sys.argv[4]
+        begin = sys.argv[4]
+        end = sys.argv[5]
         build_id = get_liveboot_build_id(job_name, build_number)
         finish_liveboot_build(build_id, begin, end)
 
index d90e6129359385b45a395e26dd402d453dca9a81..5bb40a9bfe8422c7f0097a2419bf6ac30e18d82d 100755 (executable)
@@ -43,7 +43,7 @@ EOF
 # add liveboot build to cidb
 #
 BUILD_START=$(date +%s)
-$SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER
+$SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER $REQUEST_ID
 
 #
 # build liveboot
@@ -55,7 +55,7 @@ rm $BUILD_SCRIPT
 # add liveboot build result to cidb
 #
 BUILD_END=$(date +%s)
-$SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER $BUILD_START $BUILD_END
+$SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER $REQUEST_ID $BUILD_START $BUILD_END
 
 # FIXME: too much sudo here...
 cd /srv/build/liveboot/builds