Apply defaults to job-templates parameters
I had the use case of a lot of projects sharing the same job template that uses a lot of variables. That requires each project to define all the variables even if they are mostly identical. This patch propose to define varialbes as 'defaults' and have them applied in the job-template magically (oneline diffs always have that feeling to me). So instead of: - project: name: project1 arch: amd64 builder: debuild lintian: true jobs: - '{name}-build-{arch}' And so on ... I can just: - defaults: name: sanebuild - project: name: project1 defaults: sanebuild jobs: - '{name}-build-{arch}' And override the arch as needed either in the project or by passing it to the job. Without this patch, the provided yamlparser fixture template_honor_defaults.yaml would raise: arch parameter missing to format echo Build arch {arch}. Given: {'': '', 'jobs': ['build-{arch}'], 'name': 'project-name'} Change-Id: Ida1e27eb47356d9cae42175743bd2fd52eb9d869
This commit is contained in:
parent
0268581fca
commit
98b69476ea
@ -108,6 +108,8 @@ If you need several jobs defined that are nearly identical, except
|
||||
perhaps in their names, SCP targets, etc., then you may use a Job
|
||||
Template to specify the particulars of the job, and then use a
|
||||
`Project`_ to realize the job with appropriate variable substitution.
|
||||
Any variables not specified at the project level will be inherited from
|
||||
the `Defaults`_.
|
||||
|
||||
A Job Template has the same syntax as a `Job`_, but you may add
|
||||
variables anywhere in the definition. Variables are indicated by
|
||||
@ -298,6 +300,12 @@ definitions unless they specify a different Default object with the
|
||||
|
||||
Will set the job description for every job created.
|
||||
|
||||
You can define variables that will be realized in a `Job Template`.
|
||||
|
||||
.. literalinclude:: /../../tests/yamlparser/fixtures/template_honor_defaults.yaml
|
||||
|
||||
Would create jobs ``build-i386`` and ``build-amd64``.
|
||||
|
||||
.. _advanced:
|
||||
|
||||
Advanced
|
||||
|
@ -270,6 +270,7 @@ class YamlParser(object):
|
||||
checksums = set([])
|
||||
for values in itertools.product(*dimensions):
|
||||
params = copy.deepcopy(project)
|
||||
params = self.applyDefaults(params)
|
||||
|
||||
expanded_values = {}
|
||||
for (k, v) in values:
|
||||
|
39
tests/yamlparser/fixtures/template_honor_defaults.xml
Normal file
39
tests/yamlparser/fixtures/template_honor_defaults.xml
Normal file
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties/>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>echo Build arch amd64.</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
||||
<BLANKLINE>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties/>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>echo Build arch i386.</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
15
tests/yamlparser/fixtures/template_honor_defaults.yaml
Normal file
15
tests/yamlparser/fixtures/template_honor_defaults.yaml
Normal file
@ -0,0 +1,15 @@
|
||||
- defaults:
|
||||
name: global
|
||||
arch: 'i386'
|
||||
|
||||
- project:
|
||||
name: project-name
|
||||
jobs:
|
||||
- 'build-{arch}'
|
||||
- 'build-{arch}':
|
||||
arch: 'amd64'
|
||||
|
||||
- job-template:
|
||||
name: 'build-{arch}'
|
||||
builders:
|
||||
- shell: "echo Build arch {arch}."
|
Loading…
Reference in New Issue
Block a user