diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index b46241e47..3a25c2a15 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -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 ^^^^^^^^^ diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index 02ca09e90..ffb29bc00 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -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')