Revert "Allow using template variables in "defaults" field."

This reverts commit 70ed22362a.

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
This commit is contained in:
Antoine Musso 2014-07-07 12:50:46 +00:00
parent 442d5c8a2c
commit ab434cc288
4 changed files with 5 additions and 76 deletions

View File

@ -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

View File

@ -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

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
<keepDependencies>false</keepDependencies>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>true</blockBuildWhenUpstreamBuilding>
<concurrentBuild>false</concurrentBuild>
<canRoam>true</canRoam>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<builders/>
<publishers/>
<buildWrappers>
<hudson.plugins.timestamper.TimestamperBuildWrapper/>
<hudson.plugins.ws__cleanup.PreBuildCleanup plugin="ws-cleanup@0.14">
<deleteDirs>false</deleteDirs>
</hudson.plugins.ws__cleanup.PreBuildCleanup>
</buildWrappers>
</project>
<BLANKLINE>
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
<keepDependencies>false</keepDependencies>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<concurrentBuild>false</concurrentBuild>
<canRoam>true</canRoam>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<builders/>
<publishers/>
<buildWrappers>
<hudson.plugins.timestamper.TimestamperBuildWrapper/>
</buildWrappers>
</project>

View File

@ -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'