Document template variable default values
Document the ability to define default values for template variables within the template definition thus removing the need to always having to set such values in job definitions. Change-Id: If4d8bfd898066b8e6350ed22f0c97eb939ae4348
This commit is contained in:
parent
398e28b3c3
commit
a54e623dc7
@ -74,6 +74,26 @@ Sometimes it is useful to have the same job name format used even
|
||||
where the template contents may vary. `Ids` provide a mechanism to
|
||||
support such use cases.
|
||||
|
||||
|
||||
Default Values for Template Variables
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
To facilitate reuse of templates with many variables that can be
|
||||
substituted, but where in most cases the same or no value is needed,
|
||||
it is possible to specify defaults for the variables within the
|
||||
templates themselves.
|
||||
|
||||
This can be used to provide common settings for particular templates.
|
||||
For example:
|
||||
|
||||
.. literalinclude::
|
||||
/../..tests/yamlparser/fixtures/template_default_variables.yaml
|
||||
:language: yaml
|
||||
|
||||
To use a default value for a variable used in the name would be
|
||||
uncommon unless it was in addition to another variable. However you
|
||||
can use `Ids`_ simplify such use cases.
|
||||
|
||||
.. _project:
|
||||
|
||||
Project
|
||||
|
44
tests/yamlparser/fixtures/template_default_variables.xml
Normal file
44
tests/yamlparser/fixtures/template_default_variables.xml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<disabled>true</disabled>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties/>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>echo "Job Name: template-variable-defaults-1-periodic"
|
||||
echo "Variable: Hello World"
|
||||
</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
||||
|
||||
<?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 "Job Name: template-variable-defaults-2-periodic"
|
||||
echo "Variable: Goodbye World"
|
||||
</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
25
tests/yamlparser/fixtures/template_default_variables.yaml
Normal file
25
tests/yamlparser/fixtures/template_default_variables.yaml
Normal file
@ -0,0 +1,25 @@
|
||||
- project:
|
||||
name: template_variable_defaults
|
||||
jobs:
|
||||
- 'template-variable-defaults-{num}':
|
||||
num: 1
|
||||
disabled_var: true
|
||||
- 'template-variable-defaults-{num}':
|
||||
test_var: Goodbye World
|
||||
num: 2
|
||||
|
||||
- job-template:
|
||||
# template specific defaults
|
||||
# empty value causes disabled_var to be ignored internally
|
||||
disabled_var:
|
||||
test_var: Hello World
|
||||
type: periodic
|
||||
|
||||
# template settings
|
||||
name: 'template-variable-defaults-{num}-{type}'
|
||||
id: 'template-variable-defaults-{num}'
|
||||
disabled: '{obj:disabled_var}'
|
||||
builders:
|
||||
- shell: |
|
||||
echo "Job Name: template-variable-defaults-{num}-{type}"
|
||||
echo "Variable: {test_var}"
|
Loading…
Reference in New Issue
Block a user