diff --git a/jenkins_jobs/modules/parameters.py b/jenkins_jobs/modules/parameters.py index 673aa493e..d984f1d74 100644 --- a/jenkins_jobs/modules/parameters.py +++ b/jenkins_jobs/modules/parameters.py @@ -171,6 +171,47 @@ def label_param(parser, xml_parent, data): 'LabelParameterDefinition') +def node_param(parser, xml_parent, data): + """yaml: node + Defines a list of nodes where this job could potentially be executed on. + Restrict where this project can be run, If your using a node or label + parameter to run your job on a particular node, you should not use the + option "Restrict where this project can be run" in the job configuration + - it will not have any effect to the selection of your node anymore! + + :arg str name: the name of the parameter + :arg str description: a description of the parameter (optional) + :arg list default-nodes: The nodes used when job gets triggered + by anything else other than manually + :arg list allowed-slaves: The nodes available for selection + when job gets triggered manually. Empty means 'All'. + :arg bool ignore-offline-nodes: Ignore nodes not online or not having + executors (default false) + + Example: + + .. literalinclude:: /../../tests/parameters/fixtures/node-param001.yaml + :language: yaml + + """ + pdef = base_param(parser, xml_parent, data, False, + 'org.jvnet.jenkins.plugins.nodelabelparameter.' + 'NodeParameterDefinition') + default = XML.SubElement(pdef, 'defaultSlaves') + if 'default-slaves' in data: + for slave in data['default-slaves']: + XML.SubElement(default, 'string').text = slave + allowed = XML.SubElement(pdef, 'allowedSlaves') + if 'allowed-slaves' in data: + for slave in data['allowed-slaves']: + XML.SubElement(allowed, 'string').text = slave + XML.SubElement(pdef, 'ignoreOfflineNodes').text = str( + data.get('ignore-offline-nodes', False)).lower() + + XML.SubElement(pdef, 'triggerIfResult').text = \ + 'multiSelectionDisallowed' + + def choice_param(parser, xml_parent, data): """yaml: choice A single selection parameter. diff --git a/setup.cfg b/setup.cfg index 9b75b8a74..5243cac77 100644 --- a/setup.cfg +++ b/setup.cfg @@ -99,6 +99,7 @@ jenkins_jobs.parameters = file=jenkins_jobs.modules.parameters:file_param label=jenkins_jobs.modules.parameters:label_param matrix-combinations=jenkins_jobs.modules.parameters:matrix_combinations_param + node=jenkins_jobs.modules.parameters:node_param password=jenkins_jobs.modules.parameters:password_param run=jenkins_jobs.modules.parameters:run_param string=jenkins_jobs.modules.parameters:string_param diff --git a/tests/parameters/fixtures/node-param001.xml b/tests/parameters/fixtures/node-param001.xml new file mode 100644 index 000000000..940095bbd --- /dev/null +++ b/tests/parameters/fixtures/node-param001.xml @@ -0,0 +1,21 @@ + + + + + + + SLAVE_NAME + Select slave + + + slave001 + slave002 + slave003 + + true + multiSelectionDisallowed + + + + + diff --git a/tests/parameters/fixtures/node-param001.yaml b/tests/parameters/fixtures/node-param001.yaml new file mode 100644 index 000000000..1a6de0bc0 --- /dev/null +++ b/tests/parameters/fixtures/node-param001.yaml @@ -0,0 +1,10 @@ +parameters: + - node: + name: SLAVE_NAME + description: "Select slave" + allowed-slaves: + - slave001 + - slave002 + - slave003 + ignore-offline-nodes: true +