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

This commit is contained in:
Jenkins 2014-07-07 10:11:26 +00:00 committed by Gerrit Code Review
commit e1ddd23483
4 changed files with 76 additions and 5 deletions

View File

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

View File

@ -172,10 +172,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')
@ -281,7 +278,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

View File

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

View File

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