do_autoincrement = False
do_cidb = False
do_cleanup = True
- do_liveboot_request = True
+ do_liveboot_request = False
do_reports = True
do_tagging = False
do_uploads = True
gitrepo = git.Repo('.')
local_branch = ENV['GIT_BRANCH']
remote_branch = os.path.join('origin', ENV['GIT_BRANCH'])
+ reports_file = os.path.join(ENV['WORKSPACE'], '../build-area/result/reports.tgz',)
# .. dput related (some overrides happening below, though)
dput_obj = dput.Dput(
# .. changelog related
daily_date = BUILD_START.strftime('%Y%m%d%H%M%S')
- fh = open('debian/changelog')
- cl = changlog(fh)
+ cl = changelog.Changelog()
+ cl.parse_changelog(open('debian/changelog'))
curr_name = cl.package
curr_version = cl.full_version
curr_dist = cl.distributions
- fh.close()
logger.info(
'Current Changelog: Package {name} with version {version} in distribution {dist}'.format(
name = curr_name,
# reset actions
# .. always include successful build packages into CIDB
do_cidb = True
+ do_liveboot_request = True
# .. only take care of changelog automation if we want it to
if ENV['GIT_BRANCH'] in AUTO_CHANGELOG_REPONAMES:
do_autoincrement = True
#FIXME: enable this once Florian acks.
#if GIT_REPO_PATH.startswith('/srv/git/dev/'):
# if ENV['GIT_BRANCH_NAME'] == 'pre-staging':
- # version = '%s~develop%s+%s+%s' %(version, daily_date, BUILD_NUMBER, current_commit[0:7])
+ # version = '%s~develop%s+%s+%s' %(version, daily_date, BUILD_NUMBER, curr_commit[0:7])
# changelog_distro = 'pre-staging'
# else:
# # use shorter date because we can
# daily_date = datetime.datetime.now().strftime('%Y%m%d')
- # version = '%s~alpha%s+%s+%s' %(version, daily_date, BUILD_NUMBER, current_commit[0:7])
+ # version = '%s~alpha%s+%s+%s' %(version, daily_date, BUILD_NUMBER, curr_commit[0:7])
# changelog_distro = 'unstable'
# .. just used for GitBuildPackage()
# ACT III: do something actually
# .. do some housekeeping first
if not do_cleanup:
- figlet('Skip cleanup')
+ figlet('Cleanup skipped')
else:
# .. reset local repository at first
logger.info('Reset and clean repository.')
gitrepo.git.fetch('--force','--prune').strip()
gitrepo.git.reset('--hard','HEAD').strip()
- gitrepo.git.execute('sudo','git','clean','-fdx').strip()
+ gitrepo.git.execute(['sudo','git','clean','-fdx']).strip()
gitrepo.git.branch('-D','%s' %(local_branch),with_exceptions=False).strip()
# .. and re-checkout the requested branch
)]
if len(files) > 0:
- logger.debug('Previous upstream tarball(s) found: %s' %(files))
+ logger.debug('Delete previous upstream tarball(s)')
cmd = [BIN_SUDO, BIN_RM, '-v']
cmd.extend(files)
- logger.debug('Executing "%s" ...' %(' '.join(cmd)))
- cmdobj = subprocess.Popen(
- cmd,
- shell=False,
- cwd='/',
- close_fds=True,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- env={'':''}
- ).wait()
-
- for line in cmdobj.stdout.readlines():
- logger.debug('%s' %(line.strip()))
-
- logger.debug('Returned with status %d' %(cmdobj.returncode))
+ ret = subprocess.Popen(
+ cmd,
+ shell=False,
+ cwd='/',
+ close_fds=True,
+ stdout=sys.stdout,
+ stderr=subprocess.STDOUT,
+ env={'':''}
+ ).wait()
+ logger.debug('"{cmd}" returns {exitcode}.'.format(
+ cmd = cmd,
+ exitcode = ret
+ ))
+ figlet('Cleanup OK')
# .. update changelog if we trust the package
if do_autoincrement:
'--no-auto-nmu',
'--',
'Generated by Jenkins build of commit {commit}'.format(
- commit = curr_commit
+ commit = curr_commit[0:7]
),
]
dist = 'squeeze',
arch = 'amd64',
pb_suite = pb_suite,
- git_commit_id = current_commit[0:7]
+ git_commit_id = curr_commit[0:7]
)
logger.info('Building ...')
ret = gbp.build()
# .. now handle the result
if ret:
logger.error(
- 'git-buildpackage returned non-zero. exitcode was: %s' % ret)
+ 'git-buildpackage failed with exitcode %d' % ret)
+ figlet('Build failed')
exit_error()
else:
logger.debug('git-buildpackage executed successfully')
+ figlet('Build OK')
# ACT V: post-build actions
# if reports.tgz exists untar it to workspace and delete it.
# reports.tgz is generated by /root/.pbuilder/hooks.d/B01-test
if not do_reports:
- figlet('Skip reports')
+ figlet('Reports skipped')
else:
try:
- reports_file = os.path.join(
- ENV['WORKSPACE'],
- '../build-area/result/reports.tgz',
- )
- subprocess.check_call(['/bin/tar', 'xzvf', '-C', ENV['WORKSPACE'], reports_file])
- subprocess.check_call(['/usr/bin/sudo' , '/bin/rm', reports_file])
+ if os.path.exists(reports_file):
+ subprocess.check_call(['/bin/tar', 'xzvf', '-C', ENV['WORKSPACE'], reports_file])
+ subprocess.check_call(['/usr/bin/sudo' , '/bin/rm', reports_file])
+ figlet('Reports OK')
except:
pass
# .. let's tag
if not do_tagging:
- figlet('Skip tagging')
+ figlet('Tagging skipped')
else:
try:
gitrepo.git.tag(version_tag)
exit_error()
logger.info('Tagged as "%s".' % version_tag)
+ figlet('Tagging OK')
# .. and upload
- if not do_upload:
- figlet('Skip upload')
+ if not do_uploads:
+ figlet('Upload skipped')
else:
try:
dput_obj.configure()
# strip epoch
- if ":" in version:
- version = version.split(":", 1)[1]
+ if ":" in new_version:
+ new_version = new_version.split(":", 1)[1]
# construct path for changes file
changes_file = os.path.join(
ENV['WORKSPACE'],
'../build-area/result/',
'{name}_{version}_amd64.changes'.format(
- name = new_name,
+ name = curr_name,
version = new_version,
)
)
# display changes file
fh = open(changes_file, 'r')
- logger.info('%s' % (fh.read()))
+ logger.info('Contents of %s\n%s' %(changes_file, fh.read()))
fh.close()
# upload changes file
dput_obj.upload(changes_file)
+ figlet('Upload OK')
+
except Exception as error:
- figlet('upload failed:')
+ figlet('Upload failed')
logger.exception(error)
# .. and add all the records to CIDB
if not do_cidb:
- figlet('Skip CIDB')
+ figlet('CIDB skipped')
else:
package_instances=[]
try:
ENV['JOB_NAME'],
ENV['BUILD_NUMBER'],
changes_file,
- version,
+ new_version,
BUILD_START,
BUILD_END,
)
+ figlet('CIDB OK')
except Exception as error:
- figlet('CIDB failed:')
+ figlet('CIDB failed')
logger.error("package instance not added to DB: ", exc_info=error)
exit_error()
# .. finally trigger the next liveboot automatically if we succeed with CIDB
if not do_liveboot_request:
- figlet('Skip Liveboot Request')
+ figlet('Liveboot skipped')
else:
if len(package_instances) > 0:
try:
add_liveboot_request(package_instances)
+ figlet('Liveboot OK')
except:
logger.debug("liveboot request failed")
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+# import standards
+import os
+import subprocess
+import sys
+from ConfigParser import SafeConfigParser
+
+# define constants
+BIN_DPUT = '/usr/bin/dput'
+
class Dput(object):
'''
TODO
def contents(self,value):
self._contents = value
- def configure(
- self,
- config = self.config,
- section = self.section,
- contents = self.contents,
- ):
- try:
- parser = SafeConfigParser()
- parser.add_section(section)
- for key, value in contents.iteritems():
- parser.set(section, str(key), str(value))
-
- filehandler = open(config, 'w')
- config.write(filehandler)
- filehandler.close()
+ def configure(self,):
+ parser = SafeConfigParser()
+ parser.add_section(self.section)
+ for key, value in self.contents.iteritems():
+ parser.set(self.section, str(key), str(value))
- logger.info('Dput configuration successfully created.')
- return True
+ filehandler = open(self.config, 'w')
+ parser.write(filehandler)
+ filehandler.close()
- except Exception as error:
- logger.error('Failed to configure dput: %s',exc_info=error)
+ return True
- return False
+ def upload(self,changes_file=None,):
- def upload(
- self,
- config = self.config,
- files = [],
- ):
-
- if len(files) == 0:
- logger.debug('Please specify at least one file to upload.')
- return False
-
- if type(files) == type(str):
- files = files.spit()
-
- try:
- cmd = [BIN_DPUT,
- '-c',
- '%s' %(config),
- '--no-upload-log',
- 'profitbricks',
- '%s' %(' '.join(files)),
- ]
-
- logger.debug('Executing "%s" ...' %(cmd))
- result = subprocess.Popen(
- cmd,
- shell=False,
- stdout=sys.stdout,
- stderr=subprocess.STDOUT,
- close_fds=True,
- cwd=os.path.dirname(config)
- ).wait()
- logger.debug('Returned with status %d' %(result))
-
- if result != 0:
- raise Exception('{cmd} failed with status code {code}'.format(
- cmd = ' '.join(cmd),
- code = result,
- ))
-
- logger.info('Dput upload successfully completed.')
+ if changes_file == None:
return True
- except Exception as error:
- logger.error('Failed to upload files: %s',exc_info=error))
-
- return False
+ cmd = [BIN_DPUT,
+ '-c',
+ '%s' %(self.config),
+ '--no-upload-log',
+ 'profitbricks',
+ '%s' %(changes_file),
+ ]
+
+ result = subprocess.Popen(
+ cmd,
+ shell=False,
+ stdout=sys.stdout,
+ stderr=subprocess.STDOUT,
+ close_fds=True,
+ cwd=os.path.dirname(self.config)
+ ).wait()
+
+ if result != 0:
+ raise Exception('{cmd} failed with status code {code}'.format(
+ cmd = ' '.join(cmd),
+ code = result,
+ ))
+
+ return True