]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
add liveboot to cidb
authorHolger Levsen <holger@layer-acht.org>
Thu, 11 Oct 2012 10:52:38 +0000 (12:52 +0200)
committerHolger Levsen <holger@layer-acht.org>
Thu, 11 Oct 2012 10:52:38 +0000 (12:52 +0200)
db_add.py
liveboot2db.py [new file with mode: 0755]
liveboot_build.sh

index 6176a2d832e8e8bf2c39c772f521791a5a10ef91..26ce25de157703f02534d03f5fe0e46c6e4d0a95 100755 (executable)
--- a/db_add.py
+++ b/db_add.py
@@ -38,14 +38,14 @@ def db_add_build(con, number, db_id):
         #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 db_add_build_result(con, build_id, start, end):
+def db_add_build_result(con, build_id, start, end, successful):
     cur = con.cursor()
     cur.execute("SAVEPOINT a")
     try:
-        cur.execute("INSERT INTO jenkins_build_result(jenkins_build_id, build_start, build_end, successful) VALUES(%s, '%s', '%s', %s) RETURNING id" % (build_id, start, end, 'true'))
+        cur.execute("INSERT INTO jenkins_build_result(jenkins_build_id, build_start, build_end, successful) VALUES(%s, to_timestamp('%s'), to_timestamp('%s'), %s) RETURNING id" % (build_id, start, end, successful))
     except psycopg2.DatabaseError as e:
         cur.execute("ROLLBACK TO a")  # have to rollback after failed command
-        #logger.debug("INSERT INTO jenkins_build_result(jenkins_build_id, build_start, build_end, successful) VALUES(%s, '%s', '%s', %s) RETURNING id" % (build_id, start, end, 'true'))
+        logger.debug("INSERT INTO jenkins_build_result(jenkins_build_id, build_start, build_end, successful) VALUES(%s, '%s', '%s', %s) RETURNING id" % (build_id, start, end, successful))
     return cur.fetchone()[0]
 
 def db_add_origin(con, origin):
@@ -93,7 +93,7 @@ def add_package_instances(origin, job_name, build_number, changes_file, version,
     logger.debug("INSERT success job %s" % job_name)
     # maybe FIXME: we could add the build already once its started, but for package builds we dont wanna add failures to the db at all
     db_build_id = db_add_build (con, build_number, db_job_id)
-    db_build_result_id = db_add_build_result (con, db_build_id, start, end)
+    db_build_result_id = db_add_build_result (con, db_build_id, start, end, 'true')
     logger.debug("INSERT success build number %s" % build_number)
     logger.debug("processing %s" %(changes_file))
     cmd = ["dcmd", '--deb', changes_file]
@@ -145,3 +145,33 @@ def get_package_instance(origin, package, version):
         return False
     if cur.fetchone():
         return True
+
+def get_liveboot_build_id(job_name, build_number):
+    con = db_connect()
+    cur = con.cursor()
+    try:
+        cur.execute("SELECT jenkins_build.id FROM jenkins_build"
+                " JOIN jenkins_job ON (jenkins_job.id = jenkins_build.jenkins_job_id)"
+                " WHERE jenkins_job.name = '%s' AND jenkins_build.jenkins_build_number = '%s'" % (job_name, build_number))
+    except psycopg2.DatabaseError as e:
+        logger.debug("SELECT jenkins_build.id FROM jenkins_build"
+                " JOIN jenkins_job ON (jenkins_job.id = jenkins_build.jenkins_job_id)"
+                " WHERE jenkins_job.name = '%s' AND jenkins_build.jenkins_build_number = '%s'" % (job_name, build_number))
+        return False
+    return cur.fetchone()[0]
+
+def add_liveboot_build(job_name, build_number):
+    con = db_connect()
+    db_job_id = db_add_job(con, job_name)
+    db_build_id = db_add_build (con, build_number, db_job_id)
+    con.commit()
+    logger.info("CIDB init for liveboot OK.")
+    return db_build_id
+
+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')
+    con.commit()
+    logger.info("CIDB update for liveboot OK.")
+    return db_build_result_id
+
diff --git a/liveboot2db.py b/liveboot2db.py
new file mode 100755 (executable)
index 0000000..ee3d393
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+from common_code import *
+from db_add import *
+
+
+if __name__ == '__main__':
+    if len(sys.argv) != 3 and len(sys.argv) !=5:
+        print("usage: %s $packages_file $origin")
+        sys.exit(1)
+
+    job_name = sys.argv[1]
+    build_number = sys.argv[2]
+
+    if len(sys.argv) != 5:
+        add_liveboot_build(job_name, build_number)
+    else:
+        begin = sys.argv[3]
+        end = sys.argv[4]
+        build_id = get_liveboot_build_id(job_name, build_number)
+        finish_liveboot_build(build_id, begin, end)
+
+
index fb4f8387831fe97d96dc59078dc65be53336bb9c..4ef4cfbb98cf8c6530f2274f604e557299d8852a 100755 (executable)
@@ -36,9 +36,25 @@ git checkout $GIT_BRANCH
 [ -d /srv/build/cache ] && mv /srv/build/cache .
 ./build.sh $BUILD_NUMBER $GIT_BRANCH $REQUEST_ID
 EOF
+
+#
+# add liveboot build to cidb
+#
+BUILD_START = $(date +%s)
+./liveboot2db.py $JOB_NAME $BUILD_NUMBER
+
+#
+# build liveboot
+#
 sudo pbuilder --execute --bindmounts /srv/build/ -- $BUILD_SCRIPT
 rm $BUILD_SCRIPT
 
+#
+# add liveboot build result to cidb
+#
+BUILD_END = $(date +%s)
+./liveboot2db.py $JOB_NAME $BUILD_NUMBER $BUILD_START $BUILD_END
+
 # FIXME: too much sudo here...
 cd /srv/build/liveboot/builds
 sudo mv *-* /srv/mirror/liveboot