time = "'%s'" % time
return time
-def db_add_build(con, db_id, number, start, end, status):
+def db_add_build(con, db_id, number, git_rev_id, start, end, status):
cur = con.cursor()
cur.execute("SAVEPOINT a")
start = harmonize_timeformat(start)
end = harmonize_timeformat(end)
try:
- cur.execute("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))
+ cur.execute("INSERT INTO jenkins_build(jenkins_job_id,"
+ " git_revision_id, jenkins_build_number, build_start,"
+ " build_end, status) VALUES(%s, %s, %s, %s, %s, '%s')"
+ " RETURNING id" % (db_id, git_rev_id, number, start, end,
+ status))
con.commit()
except psycopg2.DatabaseError as e:
cur.execute("ROLLBACK TO a") # have to rollback after failed command
- logger.debug("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))
+ logger.debug("INSERT INTO jenkins_build(jenkins_job_id,"
+ " git_revision_id, jenkins_build_number, build_start,"
+ " build_end, status) VALUES(%s, %s, %s, %s, '%s')"
+ " RETURNING id" % (db_id, git_rev_id, number, start, end,
+ status))
+
return cur.fetchone()[0]
def db_update_build(con, db_id, end, status):
#logger.debug("INSERT INTO deb_package(name) VALUES('%s') RETURNING id" % (package))
return cur.fetchone()[0]
+def db_add_git_repo(con, name, url):
+ cur = con.cursor()
+ cur.execute("SAVEPOINT a")
+ try:
+ cur.execute("INSERT INTO git_repository(name, url) VALUES('%s', '%s') RETURNING id" % (name, url))
+ con.commit()
+ except psycopg2.DatabaseError as e:
+ # record already exist
+ cur.execute("ROLLBACK TO a") # have to rollback after failed command
+ cur.execute("SELECT id FROM git_repository WHERE name='%s' OR URL='%s'"
+ % (name, url))
+ return cur.fetchone()[0]
+
+def db_add_git_rev(con, git_repo_id, rev):
+ cur = con.cursor()
+ cur.execute("SAVEPOINT a")
+ try:
+ cur.execute("INSERT INTO git_revision(git_repository_id, revision) "
+ "VALUES('%s', '%s') RETURNING id" % (git_repo_id, rev))
+ con.commit()
+ except psycopg2.DatabaseError as e:
+ # record already exist
+ cur.execute("ROLLBACK TO a") # have to rollback after failed command
+ cur.execute("SELECT id FROM git_revision WHERE git_repository_id='%s' "
+ "AND revision='%s'" % (git_repo_id, rev))
+ return cur.fetchone()[0]
+
def db_add_package_instance(con, package_id, origin_id, build_id, version):
cur = con.cursor()
cur.execute("SAVEPOINT a")
exit_error()
return cur.fetchone()[0]
-def add_package_instances(origin, job_name, build_number, changes_file, version, start, end):
+def add_package_instances(origin, job_name, build_number, changes_file,
+ version, start, end, git_repo_name, git_repo_url,
+ git_rev):
con = db_connect()
logger.debug("save %s to database" %(job_name))
db_origin_id = db_add_origin(con, origin)
logger.debug("INSERT success origin %s" % origin)
+ db_git_repo_id = db_add_git_repo(con, git_repo_name, git_repo_url)
+ db_git_rev_id = db_add_git_rev(con, db_git_repo_id, git_rev)
db_job_id = db_add_job(con, job_name)
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, db_job_id, build_number, start, end, 'successful')
+ db_build_id = db_add_build (con, db_job_id, build_number, db_git_rev_id,
+ start, end, 'successful')
logger.debug("INSERT success build number %s" % build_number)
logger.debug("processing %s" %(changes_file))
cmd = ["dcmd", '--deb', changes_file]
con.commit()
logger.info("CIDB update for liveboot OK.")
return
-