Check out the appropriate branch in executor
This mimics the behavior of Zuul cloner and allows the user to specify what branches of each repo should be checked out in the jobdir at the start of the job. (Of course, the job is free to check out other branches as needed; all of them will have the appropriate future state.) Change-Id: I93af5c49cb0404944636c7e63d203cdb564b267c
This commit is contained in:
parent
f327c5771a
commit
2ec590b606
@ -261,6 +261,10 @@ class ExecutorClient(object):
|
|||||||
params['timeout'] = job.timeout
|
params['timeout'] = job.timeout
|
||||||
params['items'] = merger_items
|
params['items'] = merger_items
|
||||||
params['projects'] = []
|
params['projects'] = []
|
||||||
|
if hasattr(item.change, 'branch'):
|
||||||
|
params['branch'] = item.change.branch
|
||||||
|
else:
|
||||||
|
params['branch'] = None
|
||||||
params['override_branch'] = job.override_branch
|
params['override_branch'] = job.override_branch
|
||||||
params['repo_state'] = item.current_build_set.repo_state
|
params['repo_state'] = item.current_build_set.repo_state
|
||||||
|
|
||||||
|
@ -587,6 +587,15 @@ class AnsibleJob(object):
|
|||||||
# a work complete result, don't run any jobs
|
# a work complete result, don't run any jobs
|
||||||
return
|
return
|
||||||
|
|
||||||
|
for project in args['projects']:
|
||||||
|
repo = repos[project['canonical_name']]
|
||||||
|
self.checkoutBranch(repo,
|
||||||
|
project['name'],
|
||||||
|
args['branch'],
|
||||||
|
args['override_branch'],
|
||||||
|
project['override_branch'],
|
||||||
|
project['default_branch'])
|
||||||
|
|
||||||
# Delete the origin remote from each repo we set up since
|
# Delete the origin remote from each repo we set up since
|
||||||
# it will not be valid within the jobs.
|
# it will not be valid within the jobs.
|
||||||
for repo in repos.values():
|
for repo in repos.values():
|
||||||
@ -641,6 +650,30 @@ class AnsibleJob(object):
|
|||||||
repo.setRef('refs/heads/' + branch, commit)
|
repo.setRef('refs/heads/' + branch, commit)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def checkoutBranch(self, repo, project_name, zuul_branch,
|
||||||
|
job_branch, project_override_branch,
|
||||||
|
project_default_branch):
|
||||||
|
branches = repo.getBranches()
|
||||||
|
if project_override_branch in branches:
|
||||||
|
self.log.info("Checking out %s project override branch %s",
|
||||||
|
project_name, project_override_branch)
|
||||||
|
repo.checkoutLocalBranch(project_override_branch)
|
||||||
|
elif job_branch in branches:
|
||||||
|
self.log.info("Checking out %s job branch %s",
|
||||||
|
project_name, job_branch)
|
||||||
|
repo.checkoutLocalBranch(job_branch)
|
||||||
|
elif zuul_branch and zuul_branch in branches:
|
||||||
|
self.log.info("Checking out %s zuul branch %s",
|
||||||
|
project_name, zuul_branch)
|
||||||
|
repo.checkoutLocalBranch(zuul_branch)
|
||||||
|
elif project_default_branch in branches:
|
||||||
|
self.log.info("Checking out %s project default branch %s",
|
||||||
|
project_name, project_default_branch)
|
||||||
|
repo.checkoutLocalBranch(project_default_branch)
|
||||||
|
else:
|
||||||
|
raise Exception("Project %s does not have the default branch %s" %
|
||||||
|
(project_name, project_default_branch))
|
||||||
|
|
||||||
def runPlaybooks(self, args):
|
def runPlaybooks(self, args):
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
|
@ -134,6 +134,10 @@ class Repo(object):
|
|||||||
origin = repo.remotes.origin
|
origin = repo.remotes.origin
|
||||||
return branch in origin.refs
|
return branch in origin.refs
|
||||||
|
|
||||||
|
def getBranches(self):
|
||||||
|
repo = self.createRepoObject()
|
||||||
|
return [x.name for x in repo.heads]
|
||||||
|
|
||||||
def getCommitFromRef(self, refname):
|
def getCommitFromRef(self, refname):
|
||||||
repo = self.createRepoObject()
|
repo = self.createRepoObject()
|
||||||
if refname not in repo.refs:
|
if refname not in repo.refs:
|
||||||
|
Loading…
Reference in New Issue
Block a user