From: Mathias Klette Date: Tue, 4 Jun 2013 10:01:42 +0000 (+0200) Subject: debian_build: use Jenkins parameter BUILD_TRIGGERS instead of commit message parsing X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=68a1b4653b6e53c0b53df2d5f5410d5e573987b9;p=profitbricks%2Fjenkins-build-scripts.git debian_build: use Jenkins parameter BUILD_TRIGGERS instead of commit message parsing commit message is still parsed for those triggers, but this happens through call_jenkins instead. this way jobs can use triggers no matter if recent commit message contains the requested trigger. --- diff --git a/debian_build.py b/debian_build.py index c1654a2..86922b4 100755 --- a/debian_build.py +++ b/debian_build.py @@ -32,8 +32,10 @@ logger = logger_init(__file__) # jenkins environment - parameters ENV.setdefault('NO_UPLOAD', '') +ENV.setdefault('BUILD_TRIGGERS', '') #ENV.setdefault('DISTRIBUTION', 'squeeze') #GIT_REPO_PATH = ENV['GIT_REPO_PATH'] +ENV['BUILD_TRIGGERS'] = ENV['BUILD_TRIGGERS'].split() # local constants BUILD_START = datetime.datetime.now() @@ -122,11 +124,7 @@ if __name__ == '__main__': gitrepo = git.Repo('.') local_branch = re.match('^(origin/)?(.*)', ENV['GIT_BRANCH']).groups()[1] remote_branch = os.path.join('origin', local_branch) - curr_commit = gitrepo.commit(ENV['GIT_COMMIT']) - # collect all 'trigger' expressions found in the commit message, i.e. - # <<< "[merge][no-test][provisioning] my commit message" - # >>> ['merge','no-test','provisioning'] - commit_triggers = re.findall('\[([^\]]+)\]', curr_commit.message) + curr_commit = gitrepo.commit(remote_branch) # id attribute used in python-git 0.3.2~RC1-1 found in wheezy if hasattr(curr_commit, 'hexsha'): curr_commit_id = curr_commit.hexsha @@ -154,6 +152,8 @@ if __name__ == '__main__': if re.match(COMMIT_TRIGGER_BRANCHES_RE, ENV['GIT_BRANCH']): do_triggers = True + else: + logger.info('Not evaluating triggers for branch ' + ENV['GIT_BRANCH']) if re.match(STABLE_BRANCHES_RE, ENV['GIT_BRANCH']): if re.match('^(ps_|dev_).*$', ENV['JOB_NAME']): @@ -295,19 +295,11 @@ if __name__ == '__main__': gitrepo.git.fetch('--force', '--prune').strip() gitrepo.git.reset('--hard', 'HEAD').strip() gitrepo.git.execute(['sudo', 'git', 'clean', '-fdx']).strip() - gitrepo.git.branch( - '-D', - '{branch}'.format(branch=local_branch), - with_exceptions=False, - ).strip() + gitrepo.git.branch('-D', local_branch, with_exceptions=False).strip() # .. and re-checkout the requested branch logger.info('Checkout branch {branch}.'.format(branch=remote_branch)) - gitrepo.git.checkout( - '-b', - '{lbranch}'.format(lbranch=local_branch), - '{rbranch}'.format(rbranch=remote_branch), - ).strip() + gitrepo.git.checkout('-b', local_branch, remote_branch).strip() logger.debug('Status is now:\n{status}'.format( status=gitrepo.git.status().strip(), )) @@ -333,10 +325,10 @@ if __name__ == '__main__': # .. do some CI magic now, if requested if do_triggers: - if 'merge' in commit_triggers and local_branch != 'integration': - if 'no-test' in commit_triggers: + if 'merge' in ENV['BUILD_TRIGGERS'] and local_branch != 'integration': + if 'no-test' in ENV['BUILD_TRIGGERS']: logger.info('Force building with tests as we also merge your branch.') - commit_triggers.remove('no-test') + ENV['BUILD_TRIGGERS'].remove('no-test') src_branch = local_branch # save the original branch dst_branch = 'integration' # define the new branch @@ -346,12 +338,12 @@ if __name__ == '__main__': gitrepo.git.checkout(dst_branch) gitrepo.git.pull() gitrepo.git.merge(src_branch) - logger.info('Checked out "{dst_branch}" branch after rebase and merge completed from branch "{src_branch}".'.format( + logger.info('Rebase and merge from branch "{src_branch} completed. Now in "{dst_branch}".'.format( dst_branch=dst_branch, src_branch=src_branch, )) - if 'no-test' in commit_triggers: + if 'no-test' in ENV['BUILD_TRIGGERS']: # debian/rules from vdc-bundles determines maven options for tests # depending whether DEB_NOTEST environment variable is defined # FIXME: ensure this environment variable is available in chroot