Allow using template variables in "defaults" field.

Change-Id: I876ab7fa61258e84b00a67325aeb9234aff8fa62
This commit is contained in:
Joao Vale 2014-04-17 16:14:50 +01:00
parent 463c84f055
commit 70ed22362a
4 changed files with 76 additions and 5 deletions
doc/source
jenkins_jobs
tests/yamlparser/fixtures

@ -290,6 +290,11 @@ 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

@ -162,10 +162,7 @@ class YamlParser(object):
return self.data.get('job-group', {}).get(name, None)
def getJobTemplate(self, name):
job = self.data.get('job-template', {}).get(name, None)
if not job:
return job
return self.applyDefaults(job)
return self.data.get('job-template', {}).get(name, None)
def applyDefaults(self, data):
whichdefaults = data.get('defaults', 'global')
@ -271,7 +268,7 @@ class YamlParser(object):
expanded_values[k] = v
params.update(expanded_values)
expanded = deep_format(template, params)
expanded = self.applyDefaults(deep_format(template, params))
# Keep track of the resulting expansions to avoid
# regenerating the exact same job. Whenever a project has

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

@ -0,0 +1,29 @@
- 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'