Add zuul.items to job vars

In v2 there was a way for a job to see all the changes being tested
with it.  This is more complicated in v3 with the addition of
multiple sources.  Fortunately, we can pass all the information we
need to accurately represent the situation to the job via an
data structure in ansible variables.

Change-Id: Ibca2065e9014ec67167057f89ef07d36103f89c7
This commit is contained in:
James E. Blair 2017-07-20 16:35:55 -07:00
parent a9fbb6c207
commit a08f459c23
2 changed files with 36 additions and 3 deletions

View File

@ -171,11 +171,30 @@ All items provide the following information as Ansible variables:
job for reporting or classification purposes.
**zuul.items**
A data structure representing the items being tested with this
change.
.. TODO: implement and document items
A list of dictionaries, each representing an item being tested with
this change with the format:
**project.name**
The name of the project, excluding hostname. E.g., `org/project`.
**project.canonical_hostname**
The canonical hostname where the project lives. E.g.,
`git.example.com`.
**project.canonical_name**
The full canonical name of the project including hostname. E.g.,
`git.example.com/org/project`.
**branch**
The target branch of the change (without the `refs/heads/` prefix).
**change**
The identifier for the change.
**patchset**
The patchset identifier for the change. If a change is revised,
this will have a different value.
Change Items
++++++++++++

View File

@ -175,6 +175,20 @@ class ExecutorClient(object):
zuul_params['oldrev'] = item.change.oldrev
if hasattr(item.change, 'newrev'):
zuul_params['newrev'] = item.change.newrev
zuul_params['items'] = []
for i in all_items:
d = dict()
d['project'] = dict(
name=i.change.project.name,
canonical_hostname=i.change.project.canonical_hostname,
canonical_name=i.change.project.canonical_name)
if hasattr(i.change, 'number'):
d['change'] = i.change.number
if hasattr(i.change, 'patchset'):
d['patchset'] = i.change.number
if hasattr(i.change, 'branch'):
d['branch'] = i.change.branch
zuul_params['items'].append(d)
# Legacy environment variables
params = dict(ZUUL_UUID=uuid,