diff --git a/jenkins_jobs/modules/parameters.py b/jenkins_jobs/modules/parameters.py index c164b09df..26255fb00 100644 --- a/jenkins_jobs/modules/parameters.py +++ b/jenkins_jobs/modules/parameters.py @@ -47,6 +47,7 @@ def base_param(parser, xml_parent, data, do_default, ptype): XML.SubElement(pdef, 'defaultValue').text = default else: XML.SubElement(pdef, 'defaultValue') + return pdef def string_param(parser, xml_parent, data): @@ -148,6 +149,33 @@ def label_param(parser, xml_parent, data): 'org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterDefinition') +def choice_param(parser, xml_parent, data): + """yaml: choice + A single selection parameter. + + :arg str name: the name of the parameter + :arg list choices: the available choices + :arg str description: a description of the parameter (optional) + + Example:: + + parameters: + - choice: + name: project + choices: + - nova + - glance + description: "On which project to run?" + """ + pdef = base_param(parser, xml_parent, data, False, + 'hudson.model.ChoiceParameterDefinition') + choices = XML.SubElement(pdef, 'choices', + {'class': 'java.util.Arrays$ArrayList'}) + a = XML.SubElement(choices, 'a', {'class': 'string-array'}) + for choice in data['choices']: + XML.SubElement(a, 'string').text = choice + + class Parameters(jenkins_jobs.modules.base.Base): sequence = 21 diff --git a/setup.py b/setup.py index ed1f872ec..2998b0da4 100644 --- a/setup.py +++ b/setup.py @@ -52,6 +52,7 @@ setup(name='jenkins_job_builder', 'file=jenkins_jobs.modules.parameters:file_param', 'text=jenkins_jobs.modules.parameters:text_param', 'label=jenkins_jobs.modules.parameters:label_param', + 'choice=jenkins_jobs.modules.parameters:choice_param', ], 'jenkins_jobs.notifications': [ 'http=jenkins_jobs.modules.notifications:http_endpoint',