Add support for Persistent Parameter

Change-Id: I947f85cb8ce85bf44b695fc45b8d56b4bee852a1
This commit is contained in:
wangdonghui 2022-01-20 11:39:46 +08:00
parent 7b621cf626
commit 50f7b49f64
17 changed files with 330 additions and 0 deletions

View File

@ -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
<persistent-parameter>`.
: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
<persistent-parameter>`.
: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
<persistent-parameter>`.
: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
<persistent-parameter>`.
: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

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<com.gem.persistentparameter.PersistentBooleanParameterDefinition>
<name>FOO</name>
<description>A persistent parameter named FOO, defaults to 'true'.</description>
<defaultValue>true</defaultValue>
<successfulOnly>true</successfulOnly>
</com.gem.persistentparameter.PersistentBooleanParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>

View File

@ -0,0 +1,6 @@
parameters:
- persistent-bool:
name: FOO
default: true
description: A persistent parameter named FOO, defaults to 'true'.
successfulOnly: true

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<com.gem.persistentparameter.PersistentBooleanParameterDefinition>
<name>FOO</name>
<description/>
<defaultValue>false</defaultValue>
<successfulOnly>false</successfulOnly>
</com.gem.persistentparameter.PersistentBooleanParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>

View File

@ -0,0 +1,3 @@
parameters:
- persistent-bool:
name: FOO

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<com.gem.persistentparameter.PersistentChoiceParameterDefinition>
<name>project</name>
<description>On which project to run?</description>
<choices class="java.util.Arrays$ArrayList">
<a class="string-array">
<string>nova</string>
<string>glance</string>
</a>
</choices>
<successfulOnly>true</successfulOnly>
</com.gem.persistentparameter.PersistentChoiceParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>

View File

@ -0,0 +1,8 @@
parameters:
- persistent-choice:
name: project
choices:
- nova
- glance
description: "On which project to run?"
successfulOnly: true

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<com.gem.persistentparameter.PersistentChoiceParameterDefinition>
<name>project</name>
<description/>
<choices class="java.util.Arrays$ArrayList">
<a class="string-array">
<string>nova</string>
<string>glance</string>
</a>
</choices>
<successfulOnly>false</successfulOnly>
</com.gem.persistentparameter.PersistentChoiceParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>

View File

@ -0,0 +1,6 @@
parameters:
- persistent-choice:
name: project
choices:
- nova
- glance

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<com.gem.persistentparameter.PersistentStringParameterDefinition>
<name>FOO</name>
<description>A persistent parameter named FOO, defaults to 'bar'.</description>
<defaultValue>bar</defaultValue>
<trim>true</trim>
<successfulOnly>true</successfulOnly>
</com.gem.persistentparameter.PersistentStringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>

View File

@ -0,0 +1,7 @@
parameters:
- persistent-string:
name: FOO
default: bar
description: A persistent parameter named FOO, defaults to 'bar'.
trim: true
successfulOnly: true

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<com.gem.persistentparameter.PersistentStringParameterDefinition>
<name>FOO</name>
<description/>
<defaultValue/>
<trim>false</trim>
<successfulOnly>false</successfulOnly>
</com.gem.persistentparameter.PersistentStringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>

View File

@ -0,0 +1,3 @@
parameters:
- persistent-string:
name: FOO

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<com.gem.persistentparameter.PersistentTextParameterDefinition>
<name>FOO</name>
<description>A persistent parameter named FOO, defaults to 'bar'.</description>
<defaultValue>bar</defaultValue>
<trim>true</trim>
<successfulOnly>true</successfulOnly>
</com.gem.persistentparameter.PersistentTextParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>

View File

@ -0,0 +1,7 @@
parameters:
- persistent-text:
name: FOO
default: bar
description: A persistent parameter named FOO, defaults to 'bar'.
trim: true
successfulOnly: true

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<com.gem.persistentparameter.PersistentTextParameterDefinition>
<name>FOO</name>
<description/>
<defaultValue/>
<trim>false</trim>
<successfulOnly>false</successfulOnly>
</com.gem.persistentparameter.PersistentTextParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>

View File

@ -0,0 +1,3 @@
parameters:
- persistent-text:
name: FOO