Merge "Move extended-choice support to parameters module"

This commit is contained in:
Jenkins 2014-12-03 23:29:47 +00:00 committed by Gerrit Code Review
commit 6a069e6468
5 changed files with 121 additions and 106 deletions

@ -219,21 +219,33 @@ def run_param(parser, xml_parent, data):
def extended_choice_param(parser, xml_parent, data):
"""yaml: extended-choice
Extended Choice Parameter
Requires the Jenkins `Extended Choice Parameter Plug-in.
Creates an extended choice parameter where values can be read from a file
Requires the Jenkins `Extended Choice Parameter Plugin.
<https://wiki.jenkins-ci.org/display/JENKINS/
Extended+Choice+Parameter+plugin>`_
:arg str name: the name of the parameter
:arg str description: a description of the parameter (optional)
:arg str type: parameter select type. Can be PT_SINGLE_SELECT,
PT_MULTI_SELECT, PT_RADIO, PT_CHECKBOX, PT_TEXTBOX
:arg str value: comma separated list of values
:arg str visible-item-count: number of lines to render for multi-select
(default 5)
:arg str name: name of the parameter
:arg str description: description of the parameter
(optional, default '')
:arg str property-file: location of property file to read from
(optional, default '')
:arg str property-key: key for the property-file (optional, default '')
:arg bool quote-value: whether to put quotes around the property
when passing to Jenkins (optional, default false)
:arg str visible-items: number of items to show in the list
(optional, default 5)
:arg str type: type of select, can be single-select, multi-select,
radio, checkbox or textbox (optional, default single-select)
:arg str value: comma separated list of values for the single select
or multi-select box (optional, default '')
:arg str default-value: used to set the initial selection of the
single-select or multi-select box (optional, default '')
:arg str default-property-file: location of property file when default
value needs to come from a property file (optional, default '')
:arg str default-property-key: key for the default property file
(optional, default '')
:arg str multi-select-delimiter: value between selections when the
parameter is a multi-select (default ,)
:arg str default-value: default selected value
parameter is a multi-select (optiona, default ',')
Example:
@ -242,35 +254,45 @@ def extended_choice_param(parser, xml_parent, data):
:language: yaml
"""
pdef = XML.SubElement(xml_parent,
'com.cwctravel.hudson.plugins.'
'extended__choice__parameter.'
'ExtendedChoiceParameterDefinition')
XML.SubElement(pdef, 'name').text = data['name']
XML.SubElement(pdef, 'description').text = data.get('description', '')
types_list = ['PT_SINGLE_SELECT',
'PT_MULTI_SELECT',
'PT_RADIO',
'PT_CHECKBOX',
'PT_TEXTBOX']
type = data['type']
if type not in types_list:
raise JenkinsJobsException(
'extended-choice type must be one of: '
+ ', '.join(types_list))
else:
XML.SubElement(pdef, 'type').text = type
pdef = base_param(parser, xml_parent, data, False,
'com.cwctravel.hudson.plugins.'
'extended__choice__parameter.'
'ExtendedChoiceParameterDefinition')
XML.SubElement(pdef, 'value').text = data.get('value', '')
XML.SubElement(pdef, 'visibleItemCount').text = data.get(
'visible-item-count', '5')
XML.SubElement(pdef, 'visibleItemCount').text = str(data.get(
'visible-items', data.get('visible-item-count', 5)))
XML.SubElement(pdef, 'multiSelectDelimiter').text = data.get(
'multi-select-delimiter', ',')
XML.SubElement(pdef, 'quoteValue').text = 'false'
XML.SubElement(pdef, 'quoteValue').text = str(data.get('quote-value',
False)).lower()
XML.SubElement(pdef, 'defaultValue').text = data.get(
'default-value', '')
choice = data.get('type', 'single-select')
choicedict = {'single-select': 'PT_SINGLE_SELECT',
'multi-select': 'PT_MULTI_SELECT',
'radio': 'PT_RADIO',
'checkbox': 'PT_CHECKBOX',
'textbox': 'PT_TEXTBOX',
'PT_SINGLE_SELECT': 'PT_SINGLE_SELECT',
'PT_MULTI_SELECT': 'PT_MULTI_SELECT',
'PT_RADIO': 'PT_RADIO',
'PT_CHECKBOX': 'PT_CHECKBOX',
'PT_TEXTBOX': 'PT_TEXTBOX'}
if choice in choicedict:
XML.SubElement(pdef, 'type').text = choicedict[choice]
else:
raise JenkinsJobsException("Type entered is not valid, must be one "
"of: single-select, multi-select, radio, "
"textbox or checkbox")
XML.SubElement(pdef, 'propertyFile').text = data.get('property-file', '')
XML.SubElement(pdef, 'propertyKey').text = data.get('property-key', '')
XML.SubElement(pdef, 'defaultPropertyFile').text = data.get(
'default-property-file', '')
XML.SubElement(pdef, 'defaultPropertyKey').text = data.get(
'default-property-key', '')
def validating_string_param(parser, xml_parent, data):
"""yaml: validating-string
@ -560,10 +582,20 @@ class Parameters(jenkins_jobs.modules.base.Base):
properties = XML.SubElement(xml_parent, 'properties')
parameters = data.get('parameters', [])
hmodel = 'hudson.model.'
if parameters:
pdefp = XML.SubElement(properties,
'hudson.model.ParametersDefinitionProperty')
pdefs = XML.SubElement(pdefp, 'parameterDefinitions')
# The conditionals here are to work around the extended_choice
# parameter also being definable in the properties module. This
# usage has been deprecated but not removed. Because it may have
# added these elements before us, we need to check if they already
# exist, and only add them if they're missing.
pdefp = properties.find(hmodel + 'ParametersDefinitionProperty')
if pdefp is None:
pdefp = XML.SubElement(properties,
hmodel + 'ParametersDefinitionProperty')
pdefs = pdefp.find('parameterDefinitions')
if pdefs is None:
pdefs = XML.SubElement(pdefp, 'parameterDefinitions')
for param in parameters:
self.registry.dispatch('parameter',
parser, pdefs, param)

@ -35,6 +35,7 @@ Example::
import xml.etree.ElementTree as XML
import jenkins_jobs.modules.base
from jenkins_jobs.errors import JenkinsJobsException
import logging
def builds_chain_fingerprinter(parser, xml_parent, data):
@ -346,78 +347,19 @@ def authorization(parser, xml_parent, data):
def extended_choice(parser, xml_parent, data):
"""yaml: extended-choice
Creates an extended choice property where values can be read from a file
Requires the Jenkins `Extended Choice Parameter Plugin.
<https://wiki.jenkins-ci.org/display/JENKINS/
Extended+Choice+Parameter+plugin>`_
:arg string name: name of the property
:arg string description: description of the property (optional, default '')
:arg string property-file: location of property file to read from
(optional, default '')
:arg string property-key: key for the property-file (optional, default '')
:arg bool quote-value: whether to put quotes around the property
when passing to Jenkins (optional, default false)
:arg string visible-items: number of items to show in the list
(optional, default 5)
:arg string type: type of select (optional, default single-select)
:arg string value: comma separated list of values for the single select
or multi-select box (optional, default '')
:arg string default-value: used to set the initial selection of the
single-select or multi-select box (optional, default '')
:arg string default-property-file: location of property file when default
value needs to come from a property file (optional, default '')
:arg string default-property-key: key for the default property file
(optional, default '')
Example::
properties:
- extended-choice:
name: FOO
description: A foo property
property-file: /home/foo/property.prop
property-key: key
quote-value: true
visible-items: 10
type: multi-select
value: foo,bar,select
default-value: foo
default-property-file: /home/property.prop
default-property-key: fookey
Use of this config option is deprecated. You should use the
`extended-choice` option in the parameter section of the job configuration
instead.
"""
logger = logging.getLogger("%s:extended_choice" % __name__)
logger.warn('Use of the extended-choice property is deprecated. You '
'should use the extended-choice option in the parameter '
'section instead.')
definition = XML.SubElement(xml_parent,
'hudson.model.ParametersDefinitionProperty')
definitions = XML.SubElement(definition, 'parameterDefinitions')
extended = XML.SubElement(definitions, 'com.cwctravel.hudson.plugins.'
'extended__choice__parameter.'
'ExtendedChoiceParameterDefinition')
XML.SubElement(extended, 'name').text = data['name']
XML.SubElement(extended, 'description').text = data.get('description', '')
XML.SubElement(extended, 'quoteValue').text = str(data.get('quote-value',
False)).lower()
XML.SubElement(extended, 'visibleItemCount').text = data.get(
'visible-items', '5')
choice = data.get('type', 'single-select')
choicedict = {'single-select': 'PT_SINGLE_SELECT',
'multi-select': 'PT_MULTI_SELECT',
'radio': 'PT_RADIO',
'checkbox': 'PT_CHECKBOX'}
if choice not in choicedict:
raise JenkinsJobsException("Type entered is not valid, must be one "
"of: single-select, multi-select, radio, "
"or checkbox")
XML.SubElement(extended, 'type').text = choicedict[choice]
XML.SubElement(extended, 'value').text = data.get('value', '')
XML.SubElement(extended, 'propertyFile').text = data.get('property-file',
'')
XML.SubElement(extended, 'propertyKey').text = data.get('property-key', '')
XML.SubElement(extended, 'defaultValue').text = data.get('default-value',
'')
XML.SubElement(extended, 'defaultPropertyFile').text = data.get(
'default-property-file', '')
XML.SubElement(extended, 'defaultPropertyKey').text = data.get(
'default-property-key', '')
parser.registry.dispatch('parameter', parser, definitions,
{'extended-choice': data})
def priority_sorter(parser, xml_parent, data):

@ -6,12 +6,16 @@
<com.cwctravel.hudson.plugins.extended__choice__parameter.ExtendedChoiceParameterDefinition>
<name>OPTIONS</name>
<description>Available options</description>
<type>PT_CHECKBOX</type>
<value>OptionA,OptionB,OptionC</value>
<visibleItemCount>2</visibleItemCount>
<multiSelectDelimiter>,</multiSelectDelimiter>
<quoteValue>false</quoteValue>
<defaultValue/>
<type>PT_CHECKBOX</type>
<propertyFile/>
<propertyKey/>
<defaultPropertyFile/>
<defaultPropertyKey/>
</com.cwctravel.hudson.plugins.extended__choice__parameter.ExtendedChoiceParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<com.cwctravel.hudson.plugins.extended__choice__parameter.ExtendedChoiceParameterDefinition>
<name>OPTIONS</name>
<description>Available options</description>
<value>foo|bar|select</value>
<visibleItemCount>2</visibleItemCount>
<multiSelectDelimiter>|</multiSelectDelimiter>
<quoteValue>true</quoteValue>
<defaultValue>foo</defaultValue>
<type>PT_MULTI_SELECT</type>
<propertyFile>/home/foo/property.prop</propertyFile>
<propertyKey>key</propertyKey>
<defaultPropertyFile>/home/property.prop</defaultPropertyFile>
<defaultPropertyKey>fookey</defaultPropertyKey>
</com.cwctravel.hudson.plugins.extended__choice__parameter.ExtendedChoiceParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>

@ -0,0 +1,14 @@
parameters:
- extended-choice:
name: OPTIONS
description: "Available options"
property-file: /home/foo/property.prop
property-key: key
quote-value: true
type: multi-select
value: "foo|bar|select"
visible-items: 2
multi-select-delimiter: '|'
default-value: foo
default-property-file: /home/property.prop
default-property-key: fookey