import time
import urllib
import fileinput
+import psycopg2
from glob import glob
from ftplib import FTP
from lib import git_helper
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'
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)
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)]
# 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))