diff options
author | Darragh Bailey <dbailey@hpe.com> | 2015-12-04 18:19:32 +0000 |
---|---|---|
committer | Darragh Bailey <daragh.bailey@gmail.com> | 2015-12-12 19:09:01 +0000 |
commit | 0cafeba626a6e945cd87394a4a928777c5d5173a (patch) | |
tree | 3babead4c0e29e09f729ba953b9205d102cb2f19 /jenkins_jobs/registry.py | |
parent | 449bb24f8f40866eb57404b8e4c5e77b529a996b (diff) | |
download | python-jenkins-job-builder-0cafeba626a6e945cd87394a4a928777c5d5173a.tar.gz python-jenkins-job-builder-0cafeba626a6e945cd87394a4a928777c5d5173a.tar.xz python-jenkins-job-builder-0cafeba626a6e945cd87394a4a928777c5d5173a.zip |
Order component retrieval to favour user defined
Prefer user defined macros over inbuilt entry points, as JJB may
accidentally use a name that has already been used by an end-user to
define a custom macro.
Warn users when they have a macro defined that masks an in-built
component to avoid accidentally changing XML generated with new
releases.
Change-Id: I6cae62d7cc40be6c4a5636a74f151fcce4cdd856
Diffstat (limited to 'jenkins_jobs/registry.py')
-rw-r--r-- | jenkins_jobs/registry.py | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/jenkins_jobs/registry.py b/jenkins_jobs/registry.py index 3c06beed..6dddc567 100644 --- a/jenkins_jobs/registry.py +++ b/jenkins_jobs/registry.py @@ -223,20 +223,24 @@ class ModuleRegistry(object): logger.debug("Cached entry point group %s = %s", component_list_type, eps) - if name in eps: + # check for macro first + component = parser.data.get(component_type, {}).get(name) + if component: + if name in eps: + logger.warn("You have a macro ('%s') defined for '%s' " + "component type that is masking an inbuilt " + "definition" % (name, component_type)) + + for b in component[component_list_type]: + # Pass component_data in as template data to this function + # so that if the macro is invoked with arguments, + # the arguments are interpolated into the real defn. + self.dispatch(component_type, + parser, xml_parent, b, component_data) + elif name in eps: func = eps[name].load() func(parser, xml_parent, component_data) else: - # Otherwise, see if it's defined as a macro - component = parser.data.get(component_type, {}).get(name) - if component: - for b in component[component_list_type]: - # Pass component_data in as template data to this function - # so that if the macro is invoked with arguments, - # the arguments are interpolated into the real defn. - self.dispatch(component_type, - parser, xml_parent, b, component_data) - else: - raise JenkinsJobsException("Unknown entry point or macro '{0}'" - " for component type: '{1}'.". - format(name, component_type)) + raise JenkinsJobsException("Unknown entry point or macro '{0}' " + "for component type: '{1}'.". + format(name, component_type)) |