From ab434cc2883b9d8db1044f6d797e99878ecfa3fb Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Mon, 7 Jul 2014 12:50:46 +0000 Subject: [PATCH] Revert "Allow using template variables in "defaults" field." This reverts commit 70ed22362a9c13ea9f3165e5747dcca281ad439c. I knew I should have tested the patch with my own templates. Doing so I discovered a nasty regression: The defaults can make use of variables passed by the project. By moving applyDEfaults to be called after deep_format is performed on job templates, any substitutioncontained withing defaults is no longer correctly replaced by project parameters. Change-Id: I69ffb3e28093af6db62962786d9275bf3ba4e115 --- doc/source/configuration.rst | 5 --- jenkins_jobs/builder.py | 7 ++-- tests/yamlparser/fixtures/templates003.xml | 40 --------------------- tests/yamlparser/fixtures/templates003.yaml | 29 --------------- 4 files changed, 5 insertions(+), 76 deletions(-) delete mode 100644 tests/yamlparser/fixtures/templates003.xml delete mode 100644 tests/yamlparser/fixtures/templates003.yaml diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index 32dfd6b95..88f4fa737 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -298,11 +298,6 @@ definitions unless they specify a different Default object with the Will set the job description for every job created. -Template variables can also be used to specify an appropriate set of -defaults for each generated job: - -.. literalinclude:: /../../tests/yamlparser/fixtures/templates003.yaml - .. _advanced: Advanced diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index a6d2bfa36..f21d3d3cc 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -172,7 +172,10 @@ class YamlParser(object): return self.data.get('job-group', {}).get(name, None) def getJobTemplate(self, name): - return self.data.get('job-template', {}).get(name, None) + job = self.data.get('job-template', {}).get(name, None) + if not job: + return job + return self.applyDefaults(job) def applyDefaults(self, data): whichdefaults = data.get('defaults', 'global') @@ -278,7 +281,7 @@ class YamlParser(object): expanded_values[k] = v params.update(expanded_values) - expanded = self.applyDefaults(deep_format(template, params)) + expanded = deep_format(template, params) # Keep track of the resulting expansions to avoid # regenerating the exact same job. Whenever a project has diff --git a/tests/yamlparser/fixtures/templates003.xml b/tests/yamlparser/fixtures/templates003.xml deleted file mode 100644 index 9d22458f4..000000000 --- a/tests/yamlparser/fixtures/templates003.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - <!-- Managed by Jenkins Job Builder --> - false - false - false - true - false - true - - - - - - - - false - - - - - - - - <!-- Managed by Jenkins Job Builder --> - false - false - false - false - false - true - - - - - - - - diff --git a/tests/yamlparser/fixtures/templates003.yaml b/tests/yamlparser/fixtures/templates003.yaml deleted file mode 100644 index e160d8a80..000000000 --- a/tests/yamlparser/fixtures/templates003.yaml +++ /dev/null @@ -1,29 +0,0 @@ -- defaults: - name: Foo - disabled: false - block-downstream: false - block-upstream: false - wrappers: - - timestamps - -- defaults: - name: Bar - disabled: false - block-downstream: false - block-upstream: true - wrappers: - - timestamps - - workspace-cleanup - -- job-template: - name: '{component}-Test' - project-type: freestyle - defaults: '{component}' - -- project: - name: Test-project - component: - - Foo - - Bar - jobs: - - '{component}-Test'