diff --git a/doc/source/user/jobs.rst b/doc/source/user/jobs.rst index 6962b8f66a..cf607b9f91 100644 --- a/doc/source/user/jobs.rst +++ b/doc/source/user/jobs.rst @@ -249,6 +249,13 @@ of item. A boolean indicating whether this project appears in the :attr:`job.required-projects` list for this job. + .. var:: _projects + :type: dict + + The same as ``projects`` but a dictionary indexed by the + ``name`` value of each entry. ``projects`` will be converted to + this. + .. var:: tenant The name of the current Zuul tenant. diff --git a/zuul/executor/client.py b/zuul/executor/client.py index 041f754a8c..ae22c8ea7a 100644 --- a/zuul/executor/client.py +++ b/zuul/executor/client.py @@ -187,6 +187,7 @@ class ExecutorClient(object): and item.change.newrev != '0' * 40): zuul_params['newrev'] = item.change.newrev zuul_params['projects'] = [] # Set below + zuul_params['_projects'] = {} # transitional to convert to dict zuul_params['items'] = [] for i in all_items: d = dict() @@ -270,14 +271,24 @@ class ExecutorClient(object): projects.add(project) for p in projects: - zuul_params['projects'].append(dict( + zuul_params['_projects'][p.canonical_name] = (dict( name=p.name, short_name=p.name.split('/')[-1], - canonical_hostname=p.canonical_hostname, + # Duplicate this into the dict too, so that iterating + # project.values() is easier for callers canonical_name=p.canonical_name, + canonical_hostname=p.canonical_hostname, src_dir=os.path.join('src', p.canonical_name), required=(p in required_projects), )) + # We are transitioning "projects" from a list to a dict + # indexed by canonical name, as it is much easier to access + # values in ansible. Existing callers are converted to + # "_projects", then once "projects" is unused we switch it, + # then convert callers back. Finally when "_projects" is + # unused it will be removed. + for cn, p in zuul_params['_projects'].items(): + zuul_params['projects'].append(p) build = Build(job, uuid) build.parameters = params