Merge "Add inventory variables for checkouts" into feature/zuulv3
This commit is contained in:
commit
0015fda37b
|
@ -172,6 +172,12 @@ of item.
|
||||||
The git ref of the item. This will be the full path (e.g.,
|
The git ref of the item. This will be the full path (e.g.,
|
||||||
`refs/heads/master` or `refs/changes/...`).
|
`refs/heads/master` or `refs/changes/...`).
|
||||||
|
|
||||||
|
.. var:: override_checkout
|
||||||
|
|
||||||
|
If the job was configured to override the branch or tag checked
|
||||||
|
out, this will contain the specified value. Otherwise, it will
|
||||||
|
be null.
|
||||||
|
|
||||||
.. var:: pipeline
|
.. var:: pipeline
|
||||||
|
|
||||||
The name of the pipeline in which the job is being run.
|
The name of the pipeline in which the job is being run.
|
||||||
|
@ -252,6 +258,12 @@ of item.
|
||||||
A boolean indicating whether this project appears in the
|
A boolean indicating whether this project appears in the
|
||||||
:attr:`job.required-projects` list for this job.
|
:attr:`job.required-projects` list for this job.
|
||||||
|
|
||||||
|
.. var:: checkout
|
||||||
|
|
||||||
|
The branch or tag that Zuul checked out for this project.
|
||||||
|
This may be influenced by the branch or tag associated with
|
||||||
|
the item as well as the job configuration.
|
||||||
|
|
||||||
.. var:: _projects
|
.. var:: _projects
|
||||||
:type: dict
|
:type: dict
|
||||||
|
|
||||||
|
|
|
@ -165,6 +165,7 @@ class ExecutorClient(object):
|
||||||
tenant=tenant.name,
|
tenant=tenant.name,
|
||||||
timeout=job.timeout,
|
timeout=job.timeout,
|
||||||
jobtags=sorted(job.tags),
|
jobtags=sorted(job.tags),
|
||||||
|
override_checkout=job.override_checkout,
|
||||||
_inheritance_path=list(job.inheritance_path))
|
_inheritance_path=list(job.inheritance_path))
|
||||||
if hasattr(item.change, 'branch'):
|
if hasattr(item.change, 'branch'):
|
||||||
zuul_params['branch'] = item.change.branch
|
zuul_params['branch'] = item.change.branch
|
||||||
|
|
|
@ -676,16 +676,19 @@ class AnsibleJob(object):
|
||||||
ref = args['zuul']['ref']
|
ref = args['zuul']['ref']
|
||||||
else:
|
else:
|
||||||
ref = None
|
ref = None
|
||||||
self.checkoutBranch(repo,
|
selected = self.checkoutBranch(repo,
|
||||||
project['name'],
|
project['name'],
|
||||||
ref,
|
ref,
|
||||||
args['branch'],
|
args['branch'],
|
||||||
args['override_branch'],
|
args['override_branch'],
|
||||||
args['override_checkout'],
|
args['override_checkout'],
|
||||||
project['override_branch'],
|
project['override_branch'],
|
||||||
project['override_checkout'],
|
project['override_checkout'],
|
||||||
project['default_branch'])
|
project['default_branch'])
|
||||||
|
# Update the inventory variables to indicate the ref we
|
||||||
|
# checked out
|
||||||
|
p = args['zuul']['_projects'][project['canonical_name']]
|
||||||
|
p['checkout'] = selected
|
||||||
# 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():
|
||||||
|
@ -764,44 +767,45 @@ class AnsibleJob(object):
|
||||||
project_default_branch):
|
project_default_branch):
|
||||||
branches = repo.getBranches()
|
branches = repo.getBranches()
|
||||||
refs = [r.name for r in repo.getRefs()]
|
refs = [r.name for r in repo.getRefs()]
|
||||||
|
selected_ref = None
|
||||||
if project_override_branch in branches:
|
if project_override_branch in branches:
|
||||||
|
selected_ref = project_override_branch
|
||||||
self.log.info("Checking out %s project override branch %s",
|
self.log.info("Checking out %s project override branch %s",
|
||||||
project_name, project_override_branch)
|
project_name, selected_ref)
|
||||||
repo.checkout(project_override_branch)
|
|
||||||
if project_override_checkout in refs:
|
if project_override_checkout in refs:
|
||||||
|
selected_ref = project_override_checkout
|
||||||
self.log.info("Checking out %s project override ref %s",
|
self.log.info("Checking out %s project override ref %s",
|
||||||
project_name, project_override_checkout)
|
project_name, selected_ref)
|
||||||
repo.checkout(project_override_checkout)
|
|
||||||
elif job_override_branch in branches:
|
elif job_override_branch in branches:
|
||||||
|
selected_ref = job_override_branch
|
||||||
self.log.info("Checking out %s job override branch %s",
|
self.log.info("Checking out %s job override branch %s",
|
||||||
project_name, job_override_branch)
|
project_name, selected_ref)
|
||||||
repo.checkout(job_override_branch)
|
|
||||||
elif job_override_checkout in refs:
|
elif job_override_checkout in refs:
|
||||||
|
selected_ref = job_override_checkout
|
||||||
self.log.info("Checking out %s job override ref %s",
|
self.log.info("Checking out %s job override ref %s",
|
||||||
project_name, job_override_checkout)
|
project_name, selected_ref)
|
||||||
repo.checkout(job_override_checkout)
|
|
||||||
elif ref and ref.startswith('refs/heads/'):
|
elif ref and ref.startswith('refs/heads/'):
|
||||||
b = ref[len('refs/heads/'):]
|
selected_ref = ref[len('refs/heads/'):]
|
||||||
self.log.info("Checking out %s branch ref %s",
|
self.log.info("Checking out %s branch ref %s",
|
||||||
project_name, b)
|
project_name, selected_ref)
|
||||||
repo.checkout(b)
|
|
||||||
elif ref and ref.startswith('refs/tags/'):
|
elif ref and ref.startswith('refs/tags/'):
|
||||||
t = ref[len('refs/tags/'):]
|
selected_ref = ref[len('refs/tags/'):]
|
||||||
self.log.info("Checking out %s tag ref %s",
|
self.log.info("Checking out %s tag ref %s",
|
||||||
project_name, t)
|
project_name, selected_ref)
|
||||||
repo.checkout(t)
|
|
||||||
elif zuul_branch and zuul_branch in branches:
|
elif zuul_branch and zuul_branch in branches:
|
||||||
|
selected_ref = zuul_branch
|
||||||
self.log.info("Checking out %s zuul branch %s",
|
self.log.info("Checking out %s zuul branch %s",
|
||||||
project_name, zuul_branch)
|
project_name, selected_ref)
|
||||||
repo.checkout(zuul_branch)
|
|
||||||
elif project_default_branch in branches:
|
elif project_default_branch in branches:
|
||||||
|
selected_ref = project_default_branch
|
||||||
self.log.info("Checking out %s project default branch %s",
|
self.log.info("Checking out %s project default branch %s",
|
||||||
project_name, project_default_branch)
|
project_name, selected_ref)
|
||||||
repo.checkout(project_default_branch)
|
|
||||||
else:
|
else:
|
||||||
raise ExecutorError("Project %s does not have the "
|
raise ExecutorError("Project %s does not have the "
|
||||||
"default branch %s" %
|
"default branch %s" %
|
||||||
(project_name, project_default_branch))
|
(project_name, project_default_branch))
|
||||||
|
repo.checkout(selected_ref)
|
||||||
|
return selected_ref
|
||||||
|
|
||||||
def runPlaybooks(self, args):
|
def runPlaybooks(self, args):
|
||||||
result = None
|
result = None
|
||||||
|
|
Loading…
Reference in New Issue