logger.info("INSERT INTO jenkins_build(jenkins_job_id, jenkins_build_number, build_start, build_end, status) VALUES(%s, %s, '%s', '%s', '%s') RETURNING id" % (db_id, number, start, end, status))
return cur.fetchone()[0]
+def db_update_build(con, db_id, end, status):
+ cur = con.cursor()
+ cur.execute("SAVEPOINT a")
+ try:
+ cur.execute("UPDATE jenkins_build SET build_end = '%s', status = '%s' WHERE id = %s RETURNING id" % (db_id, end, status))
+ except psycopg2.DatabaseError as e:
+ cur.execute("ROLLBACK TO a") # have to rollback after failed command
+ logger.info("UPDATE jenkins_build SET build_end = '%s', status = '%s' WHERE id = %s RETURNING id" % (db_id, end, status))
+ return cur.fetchone()[0]
+
def db_add_origin(con, origin):
cur = con.cursor()
cur.execute("SAVEPOINT a")
return False
return cur.fetchone()[0]
-def add_liveboot_build(job_name, build_number, request_id):
+def add_liveboot_build(job_name, build_number, request_id, start):
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, db_build_id)
+ db_build_id = db_add_build(con, db_job_id, build_number, start, 'NULL', 'in progress')
+ db_add_requested_liveboot_build(con, request_id, db_build_id)
con.commit()
logger.info("CIDB init for liveboot OK.")
return
-def finish_liveboot_build(build_id, start, end):
+def finish_liveboot_build(build_id, end):
con = db_connect()
- db_add_build_result (con, build_id, start, end, 'successful')
+ db_update_build(con, build_id, end, 'successful')
con.commit()
logger.info("CIDB update for liveboot OK.")
return
if __name__ == '__main__':
- if len(sys.argv) != 4 and len(sys.argv) !=6:
+ if len(sys.argv) != 5 and len(sys.argv) !=6:
# if the build was just started:
- print("usage: %s $job_name $build_number $liveboot_request_id")
+ 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")
job_name = sys.argv[1]
build_number = sys.argv[2]
request_id = sys.argv[3]
+ start = sys.argv[4]
if len(sys.argv) != 6:
- add_liveboot_build(job_name, build_number, request_id)
+ add_liveboot_build(job_name, build_number, request_id, start)
else:
- 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)
+ finish_liveboot_build(build_id, end)