]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
first sql query: add job name after build
authorHolger Levsen <holger@layer-acht.org>
Thu, 20 Sep 2012 11:05:49 +0000 (13:05 +0200)
committerHolger Levsen <holger@layer-acht.org>
Thu, 20 Sep 2012 11:05:49 +0000 (13:05 +0200)
debian_build.py

index 6c2a8aedaac53cd55bdd092e7220303aa452330d..0f41fc4c94710c93c0ec788df723880fd9a2e9e1 100755 (executable)
@@ -18,6 +18,7 @@ import subprocess
 import time
 import urllib
 import fileinput
+import psycopg2
 from glob import glob
 from ftplib import FTP
 from lib import git_helper
@@ -28,7 +29,13 @@ from ConfigParser import SafeConfigParser
 
 JOB_URL = 'http://jenkins:80/job/%(flavour)s/buildWithParameters?token=BuildIt&'
 JOB_DELAY = '0sec'
-JOB_NAME = os.environ.get('JOB_NAME')
+
+DB_USER = "liveboot"
+DB_PASSWD = "liveboot"
+DB_NAME = "liveboot"
+DB_HOST = "sagunt"
+DB_PORT = 5432
+
 
 GIT = '/usr/bin/git'
 BIN_RM = '/bin/rm'
@@ -49,6 +56,7 @@ BUILD_NUMBER = os.environ.get('BUILD_NUMBER')
 BUILD_ID = os.environ.get('BUILD_ID')
 BUILD_URL = os.environ.get('BUILD_URL')
 BUILD_AREA = os.path.abspath(os.path.join(os.curdir,'../build-area'))
+BUILD_JOBNAME = os.environ.get('JOB_NAME')
 
 GIT_REPO_PATH = os.environ.get('GIT_REPO_PATH')
 GIT_REPO_NAME = os.path.basename(GIT_REPO_PATH)
@@ -112,6 +120,31 @@ def read_file(path):
         fh.close()
         return result
 
+def db_connect():
+    return psycopg2.connect(database=DB_NAME, user=DB_USER, password=DB_PASSWD,
+            host=DB_HOST, port=DB_PORT)
+
+
+
+def db_add_job(con, name):
+    cur = con.cursor()
+    cur.execute("SAVEPOINT a")
+    try:
+        cur.execute("INSERT INTO jenkins_job(name) VALUES(%s)"
+                " RETURNING id", (name))
+    except psycopg2.DatabaseError as e:
+    # record already exist
+        cur.execute("ROLLBACK TO a")  # have to rollback after failed command
+
+#def add_package_instance("profitbricks", $BUILD_JOBNAME, $BUILD_NUMBER, changes_file)
+def add_package_instance(origin, job_name, job_id, changes_file, version):
+    con = db_connect()
+    db_add_job(con, job_name) 
+    # add jenkins_build
+    # for all packages in changes file
+      # add deb_package (if not exist)
+      # add deb_package_instance
+
 def dput_package_upload(changes_path):
     try:
         cmd = [BIN_DPUT, '-c', '%s' %(DPUT_CF), '--no-upload-log', 'profitbricks', '%s' %(changes_path)]
@@ -565,6 +598,9 @@ if __name__ == '__main__':
         # upload (if NO_UPLOAD is not set)
         if NO_UPLOAD not in ('true', 'True'):
             dput_package_upload(changes_file)
+            # cidb wise, we only care about builds from master
+            if GIT_BRANCH_NAME == 'master' or GIT_BRANCH_NAME.startswith('hotfix/'):
+                add_package_instance("profitbricks", $BUILD_JOBNAME, $BUILD_NUMBER, changes_file, version)
         else:
             logger.debug('value of NO_UPLOAD: %s' % NO_UPLOAD)
         logger.info('dist: %s' %(pb_suite))