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:
Artem Nikitin 2021-07-09 16:29:45 +03:00
parent 15b46e316f
commit 7f803887ee
3 changed files with 86 additions and 8 deletions

View File

@ -1460,12 +1460,35 @@ class Parameters(jenkins_jobs.modules.base.Base):
pdefs = XML.SubElement(pdefp, "parameterDefinitions")
for param in parameters:
# Pass job name to the uno-choice plugin
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 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"]
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)

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</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>

View 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