Fix uno-choice pluggin parameter macro usage
If the parameter is used in a macro, special fields from the job layer (`_project-name`, `_project-full-name`) were not initialized. Change-Id: Ie70f592c8ee71c3b8e1cfc3c2ba578e814af0a29
This commit is contained in:
parent
15b46e316f
commit
7f803887ee
@ -1460,6 +1460,7 @@ class Parameters(jenkins_jobs.modules.base.Base):
|
||||
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",
|
||||
@ -1468,4 +1469,26 @@ class Parameters(jenkins_jobs.modules.base.Base):
|
||||
):
|
||||
param[param_type]["_project-name"] = data["name"].split("/")[-1]
|
||||
param[param_type]["_project-full-name"] = data["name"]
|
||||
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.registry.dispatch("parameter", pdefs, param)
|
||||
|
40
tests/macros/fixtures/parameter/active-choices-macro001.xml
Normal file
40
tests/macros/fixtures/parameter/active-choices-macro001.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 ['param1', 'param2']
|
||||
</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>
|
15
tests/macros/fixtures/parameter/active-choices-macro001.yaml
Normal file
15
tests/macros/fixtures/parameter/active-choices-macro001.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
- parameter:
|
||||
name: p_ACTIVE_CHOICES
|
||||
parameters:
|
||||
- active-choices:
|
||||
name: ACTIVE_CHOICES
|
||||
description: >-
|
||||
Active choices.
|
||||
script:
|
||||
groovy: |
|
||||
return ['param1', 'param2']
|
||||
|
||||
- job:
|
||||
name: my-job
|
||||
parameters:
|
||||
- p_ACTIVE_CHOICES
|
Loading…
x
Reference in New Issue
Block a user