From b5426852449369cea958dbc0ac13e7e5b23b96a3 Mon Sep 17 00:00:00 2001 From: Andrey Pavlov Date: Thu, 27 Nov 2014 16:15:08 +0300 Subject: [PATCH] Add 'node' parameter to 'parameters' This parameter defines a list of nodes where this job could potentially be executed on. Nodes can be choosen from list of current available nodes. Currently it trasforms to single-selection dropdown to choose a slave for execution. Change-Id: I5379d20b94e3b33360ea8f842e3b4237b491addb --- jenkins_jobs/modules/parameters.py | 41 ++++++++++++++++++++ setup.cfg | 1 + tests/parameters/fixtures/node-param001.xml | 21 ++++++++++ tests/parameters/fixtures/node-param001.yaml | 10 +++++ 4 files changed, 73 insertions(+) create mode 100644 tests/parameters/fixtures/node-param001.xml create mode 100644 tests/parameters/fixtures/node-param001.yaml 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 +