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
This commit is contained in:
Andrey Pavlov 2014-11-27 16:15:08 +03:00
parent 084eb8122f
commit b542685244
4 changed files with 73 additions and 0 deletions

View File

@ -171,6 +171,47 @@ def label_param(parser, xml_parent, data):
'LabelParameterDefinition') '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): def choice_param(parser, xml_parent, data):
"""yaml: choice """yaml: choice
A single selection parameter. A single selection parameter.

View File

@ -99,6 +99,7 @@ jenkins_jobs.parameters =
file=jenkins_jobs.modules.parameters:file_param file=jenkins_jobs.modules.parameters:file_param
label=jenkins_jobs.modules.parameters:label_param label=jenkins_jobs.modules.parameters:label_param
matrix-combinations=jenkins_jobs.modules.parameters:matrix_combinations_param matrix-combinations=jenkins_jobs.modules.parameters:matrix_combinations_param
node=jenkins_jobs.modules.parameters:node_param
password=jenkins_jobs.modules.parameters:password_param password=jenkins_jobs.modules.parameters:password_param
run=jenkins_jobs.modules.parameters:run_param run=jenkins_jobs.modules.parameters:run_param
string=jenkins_jobs.modules.parameters:string_param string=jenkins_jobs.modules.parameters:string_param

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterDefinition>
<name>SLAVE_NAME</name>
<description>Select slave</description>
<defaultSlaves/>
<allowedSlaves>
<string>slave001</string>
<string>slave002</string>
<string>slave003</string>
</allowedSlaves>
<ignoreOfflineNodes>true</ignoreOfflineNodes>
<triggerIfResult>multiSelectionDisallowed</triggerIfResult>
</org.jvnet.jenkins.plugins.nodelabelparameter.NodeParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>

View File

@ -0,0 +1,10 @@
parameters:
- node:
name: SLAVE_NAME
description: "Select slave"
allowed-slaves:
- slave001
- slave002
- slave003
ignore-offline-nodes: true