From f20aed7ba38bb2da3faacafaf1517259b34d18e7 Mon Sep 17 00:00:00 2001 From: Barnaby Court Date: Tue, 11 Nov 2014 09:02:18 -0500 Subject: [PATCH] Add support for the matrix-combinations plugin This plugin allows a user to choose which matrix combinations they want to run, as opposed to the default behaviour where jenkins runs all combinations Requires the Jenkins Matrix Combinations Plugin: https://wiki.jenkins-ci.org/display/JENKINS/Matrix+Combinations+Plugin Change-Id: I13205c81aa11523a4c3fc373820eb74863d0c7ca --- jenkins_jobs/modules/parameters.py | 34 +++++++++++++++++++ setup.cfg | 1 + .../fixtures/matrix-combinations-param001.xml | 14 ++++++++ .../matrix-combinations-param001.yaml | 5 +++ 4 files changed, 54 insertions(+) create mode 100644 tests/parameters/fixtures/matrix-combinations-param001.xml create mode 100644 tests/parameters/fixtures/matrix-combinations-param001.yaml diff --git a/jenkins_jobs/modules/parameters.py b/jenkins_jobs/modules/parameters.py index 82316ff35..fa366a84b 100644 --- a/jenkins_jobs/modules/parameters.py +++ b/jenkins_jobs/modules/parameters.py @@ -514,6 +514,40 @@ def dynamic_scriptler_param_common(parser, xml_parent, data, ptype): 'read-only', False)).lower() +def matrix_combinations_param(parser, xml_parent, data): + """yaml: matrix-combinations + Matrix combinations parameter + Requires the Jenkins `Matrix Combinations Plugin. + `_ + + :arg str name: the name of the parameter + :arg str description: a description of the parameter (optional) + :arg str filter: Groovy expression to use filter the combination by + default (optional) + + Example: + + .. literalinclude:: \ + /../../tests/parameters/fixtures/matrix-combinations-param001.yaml + :language: yaml + + """ + element_name = 'hudson.plugins.matrix__configuration__parameter.' \ + 'MatrixCombinationsParameterDefinition' + pdef = XML.SubElement(xml_parent, element_name) + if 'name' not in data: + raise JenkinsJobsException('matrix-combinations must have a name ' + 'parameter.') + XML.SubElement(pdef, 'name').text = data['name'] + XML.SubElement(pdef, 'description').text = data.get('description', '') + combination_filter = data.get('filter') + if combination_filter: + XML.SubElement(pdef, 'defaultCombinationFilter').text = \ + combination_filter + + return pdef + + class Parameters(jenkins_jobs.modules.base.Base): sequence = 21 diff --git a/setup.cfg b/setup.cfg index 58f5290c0..bd4d0a44d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -96,6 +96,7 @@ jenkins_jobs.parameters = extended-choice=jenkins_jobs.modules.parameters:extended_choice_param file=jenkins_jobs.modules.parameters:file_param label=jenkins_jobs.modules.parameters:label_param + matrix-combinations=jenkins_jobs.modules.parameters:matrix_combinations_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/matrix-combinations-param001.xml b/tests/parameters/fixtures/matrix-combinations-param001.xml new file mode 100644 index 000000000..5ff7fee90 --- /dev/null +++ b/tests/parameters/fixtures/matrix-combinations-param001.xml @@ -0,0 +1,14 @@ + + + + + + + FOO + Select matrix combinations + platform == foo + + + + + diff --git a/tests/parameters/fixtures/matrix-combinations-param001.yaml b/tests/parameters/fixtures/matrix-combinations-param001.yaml new file mode 100644 index 000000000..54d73326f --- /dev/null +++ b/tests/parameters/fixtures/matrix-combinations-param001.yaml @@ -0,0 +1,5 @@ +parameters: + - matrix-combinations: + name: FOO + description: "Select matrix combinations" + filter: "platform == foo"