From e1913ab0cce5cf33f0f9439b798d92f4ac4df7ac Mon Sep 17 00:00:00 2001 From: Jaime Flynn Date: Wed, 8 Apr 2015 15:58:49 -0500 Subject: [PATCH] added support for NodeLabel parameter in trigger-builds Updated trigger-builds to take NodeLabel parameter name and value Updated unit tests Change-Id: I7ea2db6d434bf8224e1e51c27f4b657141bf86f0 --- jenkins_jobs/modules/builders.py | 15 +++++++++++++++ tests/builders/fixtures/trigger-builds006.xml | 4 ++++ tests/builders/fixtures/trigger-builds006.yaml | 2 ++ 3 files changed, 21 insertions(+) diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index a997871f0..9211b63df 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -298,6 +298,12 @@ def trigger_builds(parser, xml_parent, data): :arg bool current-parameters: Whether to include the parameters passed to the current build to the triggered job. + :arg str node-label-name: Define a name for the NodeLabel parameter to be + set. Used in conjunction with node-label. Requires NodeLabel Parameter + Plugin (optional) + :arg str node-label: Label of the nodes where build should be triggered. + Used in conjunction with node-label-name. Requires NodeLabel Parameter + Plugin (optional) :arg bool svn-revision: Whether to pass the svn revision to the triggered job :arg bool git-revision: Whether to pass the git revision @@ -432,6 +438,15 @@ def trigger_builds(parser, xml_parent, data): XML.SubElement(param, 'value').text = str( bool_param.get('value', False)).lower() + if 'node-label-name' in project_def and 'node-label' in project_def: + node = XML.SubElement(tconfigs, 'org.jvnet.jenkins.plugins.' + 'nodelabelparameter.parameterizedtrigger.' + 'NodeLabelBuildParameter') + XML.SubElement(node, 'name').text = \ + project_def.get('node-label-name') + XML.SubElement(node, 'nodeLabel').text = \ + project_def.get('node-label') + if(len(list(tconfigs)) == 0): tconfigs.set('class', 'java.util.Collections$EmptyList') diff --git a/tests/builders/fixtures/trigger-builds006.xml b/tests/builders/fixtures/trigger-builds006.xml index e8dee7cb6..5102fd67d 100644 --- a/tests/builders/fixtures/trigger-builds006.xml +++ b/tests/builders/fixtures/trigger-builds006.xml @@ -12,6 +12,10 @@ FOO="bar" + + NODE + testnodes + build_started ALWAYS diff --git a/tests/builders/fixtures/trigger-builds006.yaml b/tests/builders/fixtures/trigger-builds006.yaml index ef739ac1a..3798a74ad 100644 --- a/tests/builders/fixtures/trigger-builds006.yaml +++ b/tests/builders/fixtures/trigger-builds006.yaml @@ -4,5 +4,7 @@ builders: predefined-parameters: FOO="bar" current-parameters: true + node-label-name: NODE + node-label: testnodes git-revision: true block: true