From dfce2400bb579903f3c75a25e03a9cb8643826d2 Mon Sep 17 00:00:00 2001 From: Kyle Rockman Date: Mon, 12 Jan 2015 16:31:24 -0600 Subject: [PATCH] Add support to configure boolean parameter in PBT This change adds support to the Parameterized Build Trigger plugin for configuring boolean parameters. Change-Id: I797fe298248c2737095b39820382a8610a102d87 Also-by: Thanh Ha Signed-off-by: Kyle Rockman --- jenkins_jobs/modules/builders.py | 19 +++++++++++++++++++ tests/builders/fixtures/trigger-builds003.xml | 16 ++++++++++++++++ .../builders/fixtures/trigger-builds003.yaml | 6 ++++++ 3 files changed, 41 insertions(+) diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index c162df0d5..5065226b5 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -285,6 +285,11 @@ def trigger_builds(parser, xml_parent, data): :arg str project: the Jenkins project to trigger :arg str predefined-parameters: key/value pairs to be passed to the job (optional) + :arg list bool-parameters: + + :Bool: * **name** (`str`) -- Parameter name + * **value** (`bool`) -- Value to set (default false) + :arg str property-file: Pass properties from file to the other job (optional) :arg bool property-file-fail-on-missing: @@ -400,6 +405,20 @@ def trigger_builds(parser, xml_parent, data): 'PredefinedBuildParameters') properties = XML.SubElement(params, 'properties') properties.text = project_def['predefined-parameters'] + + if 'bool-parameters' in project_def: + params = XML.SubElement(tconfigs, + 'hudson.plugins.parameterizedtrigger.' + 'BooleanParameters') + configs = XML.SubElement(params, 'configs') + for bool_param in project_def['bool-parameters']: + param = XML.SubElement(configs, + 'hudson.plugins.parameterizedtrigger.' + 'BooleanParameterConfig') + XML.SubElement(param, 'name').text = str(bool_param['name']) + XML.SubElement(param, 'value').text = str( + bool_param.get('value', False)).lower() + if(len(list(tconfigs)) == 0): tconfigs.set('class', 'java.util.Collections$EmptyList') diff --git a/tests/builders/fixtures/trigger-builds003.xml b/tests/builders/fixtures/trigger-builds003.xml index 74278e3c3..492f91d4b 100644 --- a/tests/builders/fixtures/trigger-builds003.xml +++ b/tests/builders/fixtures/trigger-builds003.xml @@ -9,6 +9,22 @@ FOO="bar" + + + + PARAM1 + false + + + PARAM2 + true + + + PARAM3 + false + + + build_started ALWAYS diff --git a/tests/builders/fixtures/trigger-builds003.yaml b/tests/builders/fixtures/trigger-builds003.yaml index 77afa2b22..0a4d9e9e9 100644 --- a/tests/builders/fixtures/trigger-builds003.yaml +++ b/tests/builders/fixtures/trigger-builds003.yaml @@ -3,5 +3,11 @@ builders: - project: "build_started" predefined-parameters: FOO="bar" + bool-parameters: + - name: "PARAM1" + value: false + - name: "PARAM2" + value: true + - name: "PARAM3" block: true same-node: true