From b972fc07eced43c546f7f4b2d995b6f0dc25a780 Mon Sep 17 00:00:00 2001 From: mostwanted Date: Tue, 19 Sep 2017 14:07:33 +0200 Subject: [PATCH] Add support for the Git Parameter Jenkins plugin Change-Id: I7522f1250de88f073c0f47149dafed7fff9ecd9f Resolves: #2000902, #2000802 Signed-off-by: Thanh Ha --- jenkins_jobs/modules/parameters.py | 106 ++++++++++++++++++ .../fixtures/git-parameter-param-full.xml | 22 ++++ .../fixtures/git-parameter-param-full.yaml | 13 +++ .../fixtures/git-parameter-param-minimal.xml | 22 ++++ .../fixtures/git-parameter-param-minimal.yaml | 3 + 5 files changed, 166 insertions(+) create mode 100644 tests/parameters/fixtures/git-parameter-param-full.xml create mode 100644 tests/parameters/fixtures/git-parameter-param-full.yaml create mode 100644 tests/parameters/fixtures/git-parameter-param-minimal.xml create mode 100644 tests/parameters/fixtures/git-parameter-param-minimal.yaml diff --git a/jenkins_jobs/modules/parameters.py b/jenkins_jobs/modules/parameters.py index f1eeaa212..fe4817085 100644 --- a/jenkins_jobs/modules/parameters.py +++ b/jenkins_jobs/modules/parameters.py @@ -868,6 +868,112 @@ def random_string_param(registry, xml_parent, data): convert_mapping_to_xml(pdef, data, mapping, fail_required=True) +def git_parameter_param(registry, xml_parent, data): + """yaml: git-parameter + This parameter allows to select a git tag, branch or revision number as + parameter in Parametrized builds. + Requires the Jenkins :jenkins-wiki:`Git Parameter Plugin + `. + + :arg str name: Name of the parameter + :arg str description: Description of the parameter (default '') + :arg str type: The type of the list of parameters (default 'PT_TAG') + + :Allowed Values: * **PT_TAG** list of all commit tags in repository - + returns Tag Name + * **PT_BRANCH** list of all branches in repository - + returns Branch Name + * **PT_BRANCH_TAG** list of all commit tags and all + branches in repository - returns Tag Name or Branch + Name + * **PT_REVISION** list of all revision sha1 in repository + followed by its author and date - returns Tag SHA1 + * **PT_PULL_REQUEST** + + :arg str branch: Name of branch to look in. Used only if listing + revisions. (default '') + :arg str branchFilter: Regex used to filter displayed branches. If blank, + the filter will default to ".*". Remote branches will be listed with + the remote name first. E.g., "origin/master" (default '.*') + :arg str tagFilter: Regex used to filter displayed branches. If blank, the + filter will default to ".*". Remote branches will be listed with the + remote name first. E.g., "origin/master" (default '*') + :arg str sortMode: Mode of sorting. (default 'NONE') + + :Allowed Values: * **NONE** + * **DESCENDING** + * **ASCENDING** + * **ASCENDING SMART** + * **DESCENDING SMART** + + :arg str defaultValue: This value is returned when list is empty. (default + '') + :arg str selectedValue: Which value is selected, after loaded parameters. + If you choose 'default', but default value is not present on the list, + nothing is selected. (default 'NONE') + + :Allowed Values: * **NONE** + * **TOP** + * **DEFAULT** + + :arg str useRepository: If in the task is defined multiple repositories + parameter specifies which the repository is taken into account. If the + parameter is not defined, is taken first defined repository. The + parameter is a regular expression which is compared with a URL + repository. (default '') + :arg bool quickFilterEnabled: When this option is enabled will show a text + field. Parameter is filtered on the fly. (default false) + + Minimal Example: + + .. literalinclude:: + /../../tests/parameters/fixtures/git-parameter-param-minimal.yaml + :language: yaml + + Full Example: + + .. literalinclude:: + /../../tests/parameters/fixtures/git-parameter-param-full.yaml + :language: yaml + """ + pdef = XML.SubElement(xml_parent, + 'net.uaznia.lukanus.hudson.plugins.gitparameter.' + 'GitParameterDefinition') + + valid_types = [ + 'PT_TAG', + 'PT_BRANCH', + 'PT_BRANCH_TAG', + 'PT_REVISION', + 'PT_PULL_REQUEST', + ] + + valid_sort_modes = [ + 'NONE', + 'ASCENDING', + 'ASCENDING SMART', + 'DESCENDING', + 'DESCENDING SMART', + ] + + valid_selected_values = ['NONE', 'TOP', 'DEFAULT'] + + mapping = [ + ('name', 'name', None), + ('description', 'description', ''), + ('type', 'type', 'PT_TAG', valid_types), + ('branch', 'branch', ''), + ('tagFilter', 'tagFilter', '*'), + ('branchFilter', 'branchFilter', '.*'), + ('sortMode', 'sortMode', 'NONE', valid_sort_modes), + ('defaultValue', 'defaultValue', ''), + ('selectedValue', 'selectedValue', 'NONE', valid_selected_values), + ('useRepository', 'useRepository', ''), + ('quickFilterEnabled', 'quickFilterEnabled', False), + ] + convert_mapping_to_xml(pdef, data, mapping, fail_required=True) + + class Parameters(jenkins_jobs.modules.base.Base): sequence = 21 diff --git a/tests/parameters/fixtures/git-parameter-param-full.xml b/tests/parameters/fixtures/git-parameter-param-full.xml new file mode 100644 index 000000000..95173f73c --- /dev/null +++ b/tests/parameters/fixtures/git-parameter-param-full.xml @@ -0,0 +1,22 @@ + + + + + + + Foo + Lorem ipsum dolor sit amet. + PT_BRANCH_TAG + baz + bam + boo + ASCENDING + bor + TOP + buh + true + + + + + diff --git a/tests/parameters/fixtures/git-parameter-param-full.yaml b/tests/parameters/fixtures/git-parameter-param-full.yaml new file mode 100644 index 000000000..fb4c05200 --- /dev/null +++ b/tests/parameters/fixtures/git-parameter-param-full.yaml @@ -0,0 +1,13 @@ +parameters: + - git-parameter: + name: Foo + description: Lorem ipsum dolor sit amet. + type: PT_BRANCH_TAG + branch: baz + tagFilter: bam + branchFilter: boo + sortMode: ASCENDING + defaultValue: bor + selectedValue: TOP + useRepository: buh + quickFilterEnabled: true diff --git a/tests/parameters/fixtures/git-parameter-param-minimal.xml b/tests/parameters/fixtures/git-parameter-param-minimal.xml new file mode 100644 index 000000000..c7b1d8960 --- /dev/null +++ b/tests/parameters/fixtures/git-parameter-param-minimal.xml @@ -0,0 +1,22 @@ + + + + + + + Foo + + PT_TAG + + * + .* + NONE + + NONE + + false + + + + + diff --git a/tests/parameters/fixtures/git-parameter-param-minimal.yaml b/tests/parameters/fixtures/git-parameter-param-minimal.yaml new file mode 100644 index 000000000..016c54b06 --- /dev/null +++ b/tests/parameters/fixtures/git-parameter-param-minimal.yaml @@ -0,0 +1,3 @@ +parameters: + - git-parameter: + name: Foo