diff --git a/jenkins_jobs/modules/parameters.py b/jenkins_jobs/modules/parameters.py index 2ae77e79c..0e122f45c 100644 --- a/jenkins_jobs/modules/parameters.py +++ b/jenkins_jobs/modules/parameters.py @@ -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) diff --git a/tests/macros/fixtures/parameter/active-choices-macro001.xml b/tests/macros/fixtures/parameter/active-choices-macro001.xml new file mode 100644 index 000000000..e4465551b --- /dev/null +++ b/tests/macros/fixtures/parameter/active-choices-macro001.xml @@ -0,0 +1,40 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + + true + + + ACTIVE_CHOICES + Active choices. + PT_SINGLE_SELECT + false + 1 + my-job + my-job + + + + + + + + + diff --git a/tests/macros/fixtures/parameter/active-choices-macro001.yaml b/tests/macros/fixtures/parameter/active-choices-macro001.yaml new file mode 100644 index 000000000..3091d166a --- /dev/null +++ b/tests/macros/fixtures/parameter/active-choices-macro001.yaml @@ -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