Merge "Fix uno-choice parameter macro processing"
This commit is contained in:
commit
6f402e76b8
@ -1590,6 +1590,19 @@ class Parameters(jenkins_jobs.modules.base.Base):
|
||||
component_type = "parameter"
|
||||
component_list_type = "parameters"
|
||||
|
||||
@staticmethod
|
||||
def _extend_uno_choice_param_data(param, param_type, data):
|
||||
"""Pass job name to the uno-choice plugin"""
|
||||
if param_type in (
|
||||
"active-choices",
|
||||
"active-choices-reactive",
|
||||
"dynamic-reference",
|
||||
):
|
||||
# Extend uno-choice plugin parameter data with mandatory properties:
|
||||
# `project-name` and `project-full-name`
|
||||
param[param_type]["_project-name"] = data["name"].split("/")[-1]
|
||||
param[param_type]["_project-full-name"] = data["name"]
|
||||
|
||||
def gen_xml(self, xml_parent, data):
|
||||
properties = xml_parent.find("properties")
|
||||
if properties is None:
|
||||
@ -1612,36 +1625,20 @@ class Parameters(jenkins_jobs.modules.base.Base):
|
||||
if pdefs is None:
|
||||
pdefs = XML.SubElement(pdefp, "parameterDefinitions")
|
||||
for param in parameters:
|
||||
# Pass job name to the uno-choice plugin
|
||||
if isinstance(param, dict):
|
||||
param_type = next(iter(param))
|
||||
if param_type in (
|
||||
"active-choices",
|
||||
"active-choices-reactive",
|
||||
"dynamic-reference",
|
||||
):
|
||||
param[param_type]["_project-name"] = data["name"].split("/")[-1]
|
||||
param[param_type]["_project-full-name"] = data["name"]
|
||||
if not isinstance(param, dict):
|
||||
# Macro parameter without arguments
|
||||
param = {param: {}}
|
||||
param_type = next(iter(param))
|
||||
component = self.registry.parser_data.get("parameter", {}).get(
|
||||
param_type
|
||||
)
|
||||
if component is None:
|
||||
self._extend_uno_choice_param_data(param, param_type, data)
|
||||
else:
|
||||
# Process macro case.
|
||||
# TODO: Find a way to do it more properly.
|
||||
# It's possible has an issue with macro parameter chain,
|
||||
# when a macro calls another macro with uno-choice plugin parameters.
|
||||
component = self.registry.parser_data.get("parameter", {}).get(
|
||||
param
|
||||
)
|
||||
for macro_param in component.get("parameters", []):
|
||||
for macro_param_type in macro_param:
|
||||
if macro_param_type in (
|
||||
"active-choices",
|
||||
"active-choices-reactive",
|
||||
"dynamic-reference",
|
||||
):
|
||||
macro_param[macro_param_type]["_project-name"] = data[
|
||||
"name"
|
||||
].split("/")[-1]
|
||||
macro_param[macro_param_type][
|
||||
"_project-full-name"
|
||||
] = data["name"]
|
||||
|
||||
self._extend_uno_choice_param_data(
|
||||
macro_param, macro_param_type, data
|
||||
)
|
||||
self.registry.dispatch("parameter", pdefs, param)
|
||||
|
39
tests/macros/fixtures/parameter/active-choices-macro002.xml
Normal file
39
tests/macros/fixtures/parameter/active-choices-macro002.xml
Normal file
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties>
|
||||
<hudson.model.ParametersDefinitionProperty>
|
||||
<parameterDefinitions>
|
||||
<org.biouno.unochoice.ChoiceParameter>
|
||||
<script class="org.biouno.unochoice.model.GroovyScript">
|
||||
<secureFallbackScript>
|
||||
<script/>
|
||||
<sandbox>true</sandbox>
|
||||
</secureFallbackScript>
|
||||
<secureScript>
|
||||
<script>return ['default_value']</script>
|
||||
<sandbox>true</sandbox>
|
||||
</secureScript>
|
||||
</script>
|
||||
<name>ACTIVE_CHOICES</name>
|
||||
<description>Active choices.</description>
|
||||
<choiceType>PT_SINGLE_SELECT</choiceType>
|
||||
<filterable>false</filterable>
|
||||
<filterLength>1</filterLength>
|
||||
<projectName>my-job</projectName>
|
||||
<projectFullName>my-job</projectFullName>
|
||||
</org.biouno.unochoice.ChoiceParameter>
|
||||
</parameterDefinitions>
|
||||
</hudson.model.ParametersDefinitionProperty>
|
||||
</properties>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders/>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
16
tests/macros/fixtures/parameter/active-choices-macro002.yaml
Normal file
16
tests/macros/fixtures/parameter/active-choices-macro002.yaml
Normal file
@ -0,0 +1,16 @@
|
||||
- parameter:
|
||||
name: p_ACTIVE_CHOICES
|
||||
parameters:
|
||||
- active-choices:
|
||||
name: ACTIVE_CHOICES
|
||||
description: >-
|
||||
Active choices.
|
||||
script:
|
||||
groovy: !j2: |
|
||||
return ['{{ default }}']
|
||||
|
||||
- job:
|
||||
name: my-job
|
||||
parameters:
|
||||
- p_ACTIVE_CHOICES:
|
||||
default: default_value
|
40
tests/macros/fixtures/parameter/active-choices-macro003.xml
Normal file
40
tests/macros/fixtures/parameter/active-choices-macro003.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties>
|
||||
<hudson.model.ParametersDefinitionProperty>
|
||||
<parameterDefinitions>
|
||||
<org.biouno.unochoice.ChoiceParameter>
|
||||
<script class="org.biouno.unochoice.model.GroovyScript">
|
||||
<secureFallbackScript>
|
||||
<script/>
|
||||
<sandbox>true</sandbox>
|
||||
</secureFallbackScript>
|
||||
<secureScript>
|
||||
<script>return ['default_value']
|
||||
</script>
|
||||
<sandbox>true</sandbox>
|
||||
</secureScript>
|
||||
</script>
|
||||
<name>ACTIVE_CHOICES</name>
|
||||
<description>Active choices.</description>
|
||||
<choiceType>PT_SINGLE_SELECT</choiceType>
|
||||
<filterable>false</filterable>
|
||||
<filterLength>1</filterLength>
|
||||
<projectName>my-job</projectName>
|
||||
<projectFullName>my-job</projectFullName>
|
||||
</org.biouno.unochoice.ChoiceParameter>
|
||||
</parameterDefinitions>
|
||||
</hudson.model.ParametersDefinitionProperty>
|
||||
</properties>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders/>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
16
tests/macros/fixtures/parameter/active-choices-macro003.yaml
Normal file
16
tests/macros/fixtures/parameter/active-choices-macro003.yaml
Normal file
@ -0,0 +1,16 @@
|
||||
- parameter:
|
||||
name: p_ACTIVE_CHOICES
|
||||
parameters:
|
||||
- active-choices:
|
||||
name: ACTIVE_CHOICES
|
||||
description: >-
|
||||
Active choices.
|
||||
script:
|
||||
groovy: |
|
||||
return ['{default}']
|
||||
|
||||
- job:
|
||||
name: my-job
|
||||
parameters:
|
||||
- p_ACTIVE_CHOICES:
|
||||
default: default_value
|
Loading…
Reference in New Issue
Block a user