diff --git a/jenkins_jobs/modules/parameters.py b/jenkins_jobs/modules/parameters.py index 4961487d2..3ff59c1af 100644 --- a/jenkins_jobs/modules/parameters.py +++ b/jenkins_jobs/modules/parameters.py @@ -1431,6 +1431,159 @@ def dynamic_reference_param(registry, xml_parent, data): helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True) +def persistent_string_param(registry, xml_parent, data): + """yaml: persistent-string + A persistent string parameter. + + Requires the Jenkins :jenkins-plugins:`Persistent Parameter Plugin + `. + + :arg str name: the name of the parameter + :arg str default: the default value of the parameter (optional) + :arg str description: a description of the parameter (optional) + :arg bool trim: strip whitespaces from the begnning and end + of the string (optional, default: false) + :arg bool successfulOnly: if true, then the value of the parameter + gets persisted only between successful builds + (optional, default: false) + + Example:: + + parameters: + - persistent-string: + name: FOO + default: bar + description: "A parameter named FOO, defaults to 'bar'." + trim: false + successfulOnly: false + """ + pdef = base_param( + registry, + xml_parent, + data, + True, + "com.gem.persistentparameter.PersistentStringParameterDefinition", + ) + + mapping = [("trim", "trim", False), ("successfulOnly", "successfulOnly", False)] + helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True) + + +def persistent_bool_param(registry, xml_parent, data): + """yaml: persistent-bool + A persistent boolean parameter. + + Requires the Jenkins :jenkins-plugins:`Persistent Parameter Plugin + `. + + :arg str name: the name of the parameter + :arg str default: the default value of the parameter (optional) + :arg str description: a description of the parameter (optional) + :arg bool successfulOnly: if true, then the value of the parameter + gets persisted only between successful builds + (optional, default: false) + + Example:: + + parameters: + - persistent-bool: + name: FOO + default: false + description: "A persistent parameter named FOO, defaults to 'false'." + successfulOnly: false + """ + data["default"] = str(data.get("default", False)).lower() + pdef = base_param( + registry, + xml_parent, + data, + True, + "com.gem.persistentparameter.PersistentBooleanParameterDefinition", + ) + + mapping = [("successfulOnly", "successfulOnly", False)] + helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True) + + +def persistent_text_param(registry, xml_parent, data): + """yaml: persistent-text + A persistent text parameter. + + Requires the Jenkins :jenkins-plugins:`Persistent Parameter Plugin + `. + + :arg str name: the name of the parameter + :arg str default: the default value of the parameter (optional) + :arg str description: a description of the parameter (optional) + :arg bool trim: strip whitespaces from the begnning and end + of the string (optional, default: false) + :arg bool successfulOnly: if true, then the value of the parameter + gets persisted only between successful builds + (optional, default: false) + + Example:: + + parameters: + - persistent-text: + name: FOO + default: bar + description: "A persistent parameter named FOO, defaults to 'bar'." + successfulOnly: false + """ + + pdef = base_param( + registry, + xml_parent, + data, + True, + "com.gem.persistentparameter.PersistentTextParameterDefinition", + ) + + mapping = [("trim", "trim", False), ("successfulOnly", "successfulOnly", False)] + helpers.convert_mapping_to_xml(pdef, data, mapping, fail_required=True) + + +def persistent_choice_param(registry, xml_parent, data): + """yaml: persistent-choice + A persistent single selection parameter. + + Requires the Jenkins :jenkins-plugins:`Persistent Parameter Plugin + `. + + :arg str name: the name of the parameter + :arg list choices: the available choices, first one is the default one. + :arg str description: a description of the parameter (optional) + :arg bool successfulOnly: if true, then the value of the parameter + gets persisted only between successful builds + (optional, default: false) + + Example:: + + parameters: + - persistent-choice: + name: project + choices: + - nova + - glance + description: "On which project to run?" + successfulOnly: false + """ + pdef = base_param( + registry, + xml_parent, + data, + False, + "com.gem.persistentparameter.PersistentChoiceParameterDefinition", + ) + choices = XML.SubElement(pdef, "choices", {"class": "java.util.Arrays$ArrayList"}) + a = XML.SubElement(choices, "a", {"class": "string-array"}) + for choice in data["choices"]: + XML.SubElement(a, "string").text = choice + + mapping = [("successfulOnly", "successfulOnly", False)] + helpers.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/persistent-bool-param-full.xml b/tests/parameters/fixtures/persistent-bool-param-full.xml new file mode 100644 index 000000000..433c8f400 --- /dev/null +++ b/tests/parameters/fixtures/persistent-bool-param-full.xml @@ -0,0 +1,15 @@ + + + + + + + FOO + A persistent parameter named FOO, defaults to 'true'. + true + true + + + + + diff --git a/tests/parameters/fixtures/persistent-bool-param-full.yaml b/tests/parameters/fixtures/persistent-bool-param-full.yaml new file mode 100644 index 000000000..f0d33a193 --- /dev/null +++ b/tests/parameters/fixtures/persistent-bool-param-full.yaml @@ -0,0 +1,6 @@ +parameters: + - persistent-bool: + name: FOO + default: true + description: A persistent parameter named FOO, defaults to 'true'. + successfulOnly: true diff --git a/tests/parameters/fixtures/persistent-bool-param-minimal.xml b/tests/parameters/fixtures/persistent-bool-param-minimal.xml new file mode 100644 index 000000000..77720ee7a --- /dev/null +++ b/tests/parameters/fixtures/persistent-bool-param-minimal.xml @@ -0,0 +1,15 @@ + + + + + + + FOO + + false + false + + + + + diff --git a/tests/parameters/fixtures/persistent-bool-param-minimal.yaml b/tests/parameters/fixtures/persistent-bool-param-minimal.yaml new file mode 100644 index 000000000..f529512aa --- /dev/null +++ b/tests/parameters/fixtures/persistent-bool-param-minimal.yaml @@ -0,0 +1,3 @@ +parameters: + - persistent-bool: + name: FOO diff --git a/tests/parameters/fixtures/persistent-choice-param-full.xml b/tests/parameters/fixtures/persistent-choice-param-full.xml new file mode 100644 index 000000000..24ba5ce2f --- /dev/null +++ b/tests/parameters/fixtures/persistent-choice-param-full.xml @@ -0,0 +1,20 @@ + + + + + + + project + On which project to run? + + + nova + glance + + + true + + + + + diff --git a/tests/parameters/fixtures/persistent-choice-param-full.yaml b/tests/parameters/fixtures/persistent-choice-param-full.yaml new file mode 100644 index 000000000..04cba4aa4 --- /dev/null +++ b/tests/parameters/fixtures/persistent-choice-param-full.yaml @@ -0,0 +1,8 @@ +parameters: + - persistent-choice: + name: project + choices: + - nova + - glance + description: "On which project to run?" + successfulOnly: true diff --git a/tests/parameters/fixtures/persistent-choice-param-minimal.xml b/tests/parameters/fixtures/persistent-choice-param-minimal.xml new file mode 100644 index 000000000..1b36fb958 --- /dev/null +++ b/tests/parameters/fixtures/persistent-choice-param-minimal.xml @@ -0,0 +1,20 @@ + + + + + + + project + + + + nova + glance + + + false + + + + + diff --git a/tests/parameters/fixtures/persistent-choice-param-minimal.yaml b/tests/parameters/fixtures/persistent-choice-param-minimal.yaml new file mode 100644 index 000000000..ddc1c2673 --- /dev/null +++ b/tests/parameters/fixtures/persistent-choice-param-minimal.yaml @@ -0,0 +1,6 @@ +parameters: + - persistent-choice: + name: project + choices: + - nova + - glance diff --git a/tests/parameters/fixtures/persistent-string-param-full.xml b/tests/parameters/fixtures/persistent-string-param-full.xml new file mode 100644 index 000000000..d514d8aec --- /dev/null +++ b/tests/parameters/fixtures/persistent-string-param-full.xml @@ -0,0 +1,16 @@ + + + + + + + FOO + A persistent parameter named FOO, defaults to 'bar'. + bar + true + true + + + + + diff --git a/tests/parameters/fixtures/persistent-string-param-full.yaml b/tests/parameters/fixtures/persistent-string-param-full.yaml new file mode 100644 index 000000000..783974fb2 --- /dev/null +++ b/tests/parameters/fixtures/persistent-string-param-full.yaml @@ -0,0 +1,7 @@ +parameters: + - persistent-string: + name: FOO + default: bar + description: A persistent parameter named FOO, defaults to 'bar'. + trim: true + successfulOnly: true diff --git a/tests/parameters/fixtures/persistent-string-param-minimal.xml b/tests/parameters/fixtures/persistent-string-param-minimal.xml new file mode 100644 index 000000000..ad4bec991 --- /dev/null +++ b/tests/parameters/fixtures/persistent-string-param-minimal.xml @@ -0,0 +1,16 @@ + + + + + + + FOO + + + false + false + + + + + diff --git a/tests/parameters/fixtures/persistent-string-param-minimal.yaml b/tests/parameters/fixtures/persistent-string-param-minimal.yaml new file mode 100644 index 000000000..cf23392d2 --- /dev/null +++ b/tests/parameters/fixtures/persistent-string-param-minimal.yaml @@ -0,0 +1,3 @@ +parameters: + - persistent-string: + name: FOO diff --git a/tests/parameters/fixtures/persistent-text-param-full.xml b/tests/parameters/fixtures/persistent-text-param-full.xml new file mode 100644 index 000000000..9f1f63bdb --- /dev/null +++ b/tests/parameters/fixtures/persistent-text-param-full.xml @@ -0,0 +1,16 @@ + + + + + + + FOO + A persistent parameter named FOO, defaults to 'bar'. + bar + true + true + + + + + diff --git a/tests/parameters/fixtures/persistent-text-param-full.yaml b/tests/parameters/fixtures/persistent-text-param-full.yaml new file mode 100644 index 000000000..d222bdb2c --- /dev/null +++ b/tests/parameters/fixtures/persistent-text-param-full.yaml @@ -0,0 +1,7 @@ +parameters: + - persistent-text: + name: FOO + default: bar + description: A persistent parameter named FOO, defaults to 'bar'. + trim: true + successfulOnly: true diff --git a/tests/parameters/fixtures/persistent-text-param-minimal.xml b/tests/parameters/fixtures/persistent-text-param-minimal.xml new file mode 100644 index 000000000..aa567f41c --- /dev/null +++ b/tests/parameters/fixtures/persistent-text-param-minimal.xml @@ -0,0 +1,16 @@ + + + + + + + FOO + + + false + false + + + + + diff --git a/tests/parameters/fixtures/persistent-text-param-minimal.yaml b/tests/parameters/fixtures/persistent-text-param-minimal.yaml new file mode 100644 index 000000000..c3e015ba7 --- /dev/null +++ b/tests/parameters/fixtures/persistent-text-param-minimal.yaml @@ -0,0 +1,3 @@ +parameters: + - persistent-text: + name: FOO