Add support for giving lists to job templates

This change allows constructs like:

- job-template:
    name: "foo-build-{slave}"

- project:
    slave:
      - debian-squeeze-powerpc
      - debian-squeeze-amd64

and will then instantiate the job template for each value in the
list.

Change-Id: I057a30ef6d91048efacc4a6da2142cb8f924dd06
Reviewed-on: https://review.openstack.org/14738
Reviewed-by: Clark Boylan <clark.boylan@gmail.com>
Approved: James E. Blair <corvus@inaugust.com>
Reviewed-by: James E. Blair <corvus@inaugust.com>
Tested-by: Jenkins
This commit is contained in:
Tollef Fog Heen 2012-10-23 13:45:19 +02:00 committed by Jenkins
parent 156c4990f9
commit 8860e647a0
2 changed files with 35 additions and 8 deletions

View File

@ -100,7 +100,21 @@ substitutions as follows::
mail-to: developer@nowhere.net
- {name}-perf-tests:
mail-to: projmanager@nowhere.net
If a variable is a list, the job template will be realized with the
variable set to each value in the list. Multiple lists will lead to
the template being realized with the cartesian product of those
values.
- project:
name: project-name
pyver:
- 26
- 27
jobs:
- {name}-{pyver}
Job Group
^^^^^^^^^

View File

@ -25,6 +25,7 @@ import re
import pkg_resources
import logging
import copy
import itertools
logger = logging.getLogger(__name__)
@ -135,15 +136,27 @@ class YamlParser(object):
# see if it's a template
template = self.getJobTemplate(jobname)
if template:
params = copy.deepcopy(project)
params.update(deep_format(jobparams, project))
logger.debug("Generating XML for template job {0}"
" (params {1})".format(
template['name'], params))
self.getXMLForTemplateJob(params, template)
d = {}
d.update(project)
d.update(jobparams)
self.getXMLForTemplateJob(d, template)
def getXMLForTemplateJob(self, project, template):
self.getXMLForJob(deep_format(template, project))
dimensions = []
for (k, v) in project.items():
if type(v) == list and k not in ['jobs']:
dimensions.append(zip([k] * len(v), v))
# XXX somewhat hackish to ensure we actually have a single
# pass through the loop
if len(dimensions) == 0:
dimensions = [(("", ""),)]
for values in itertools.product(*dimensions):
params = copy.deepcopy(project)
params.update(values)
logger.debug("Generating XML for template job {0}"
" (params {1})".format(
template['name'], params))
self.getXMLForJob(deep_format(template, params))
def getXMLForJob(self, data):
kind = data.get('project-type', 'freestyle')