From d06da2be2e81187b726a17d48efa557ce0731448 Mon Sep 17 00:00:00 2001 From: hyokeun Date: Fri, 18 Aug 2017 15:07:42 +0900 Subject: [PATCH] TPE-181 Check tag before SR submit from dashboard Change-Id: I4f28d94016c519103a9402494e590e60790094bf --- job_add_git_tag.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/job_add_git_tag.py b/job_add_git_tag.py index 8a0e5f5..c364e19 100644 --- a/job_add_git_tag.py +++ b/job_add_git_tag.py @@ -105,7 +105,7 @@ def main(): for proj, commit in zip(projects, commit_ids): # prepare separate temp directory for each build - prjdir = os.path.join(git_cache, proj) + prjdir = os.path.join(os.getenv('WORKSPACE'), proj) print "Cloning project %s..." % proj # clone gerrit project to local dir @@ -114,9 +114,9 @@ def main(): mygit = Git(prjdir) + # masquerade user name/ email cur_dir = os.getcwd() os.chdir(prjdir) - # masquerade user name/ email gitcmd = "git config user.name \"%s\"" % (event['tagger_username']) if runner.show(gitcmd)[0] != 0: raise Exception("failed to execute %s" % gitcmd) @@ -128,27 +128,28 @@ def main(): branches = mygit.branch_contains(commit) if event['branch'] not in branches: raise LocalError("commit %s is not in branch %s" % (commit, event['branch'])) - - for proj, commit in zip(projects, commit_ids): - print "Now creating tag for %s" %proj - prjdir = os.path.join(git_cache, proj) - mygit = Git(prjdir) + print "Now creating tag for %s" %proj mygit.set_branch(event['branch']) mygit.checkout(commit) - if 'sr_tag' in event: tag_name = event['sr_tag'] - - mygit.create_tag(tag_name, event['tagger_submit_message']) - - mygit.push_tag("origin", tag_name) global sr_tag sr_tag = tag_name + try: + mygit.create_tag(tag_name, event['tagger_submit_message']) + except Exception as err: + raise LocalError('Tag already exist %s' % proj) - revert_git_config() - return 0 + for proj, commit in zip(projects, commit_ids): + print "Now creating tag for %s" %proj + prjdir = os.path.join(os.getenv('WORKSPACE'), proj) + mygit = Git(prjdir) + mygit.set_branch(event['branch']) + mygit.checkout(commit) + mygit.push_tag("origin", tag_name) + return 0 if __name__ == '__main__': exit_status = 0 @@ -157,9 +158,8 @@ if __name__ == '__main__': exit_status = main() except Exception as err: print err - error_string = err + error_string = repr(err) exit_status = 1 - revert_git_config() # status is changed to 'Succeeded' or 'Failed' status_str = "Processing" @@ -177,3 +177,4 @@ if __name__ == '__main__': trigger_next("BUILD-MONITOR", bm_data); sys.exit(exit_status) + -- 2.7.4