Merge "Allow template-name in the global defaults"
This commit is contained in:
commit
5da4f97e23
|
@ -437,6 +437,9 @@ You can define variables that will be realized in a `Job Template`.
|
||||||
|
|
||||||
Would create jobs ``build-i386`` and ``build-amd64``.
|
Would create jobs ``build-i386`` and ``build-amd64``.
|
||||||
|
|
||||||
|
You can also reference a variable ``{template-name}`` in any value and it will
|
||||||
|
be subtitued by the name of the current job template being processed.
|
||||||
|
|
||||||
.. _variable_references:
|
.. _variable_references:
|
||||||
|
|
||||||
Variable References
|
Variable References
|
||||||
|
|
|
@ -33,7 +33,9 @@ def deep_format(obj, paramdict, allow_empty=False):
|
||||||
# limitations on the values in paramdict - the post-format result must
|
# limitations on the values in paramdict - the post-format result must
|
||||||
# still be valid YAML (so substituting-in a string containing quotes, for
|
# still be valid YAML (so substituting-in a string containing quotes, for
|
||||||
# example, is problematic).
|
# example, is problematic).
|
||||||
if hasattr(obj, 'format'):
|
if getattr(obj, 'verbatim', False) is True:
|
||||||
|
ret = obj
|
||||||
|
elif hasattr(obj, 'format'):
|
||||||
try:
|
try:
|
||||||
ret = CustomFormatter(allow_empty).format(obj, **paramdict)
|
ret = CustomFormatter(allow_empty).format(obj, **paramdict)
|
||||||
except KeyError as exc:
|
except KeyError as exc:
|
||||||
|
@ -129,3 +131,10 @@ class CustomFormatter(Formatter):
|
||||||
)
|
)
|
||||||
return ''
|
return ''
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
class VerbatimString(str):
|
||||||
|
"""
|
||||||
|
String which is not expanded by `deep_format`.
|
||||||
|
"""
|
||||||
|
verbatim = True
|
||||||
|
|
|
@ -24,7 +24,7 @@ import os
|
||||||
|
|
||||||
from jenkins_jobs.constants import MAGIC_MANAGE_STRING
|
from jenkins_jobs.constants import MAGIC_MANAGE_STRING
|
||||||
from jenkins_jobs.errors import JenkinsJobsException
|
from jenkins_jobs.errors import JenkinsJobsException
|
||||||
from jenkins_jobs.formatter import deep_format
|
from jenkins_jobs.formatter import deep_format, VerbatimString
|
||||||
import jenkins_jobs.local_yaml as local_yaml
|
import jenkins_jobs.local_yaml as local_yaml
|
||||||
from jenkins_jobs import utils
|
from jenkins_jobs import utils
|
||||||
|
|
||||||
|
@ -346,6 +346,7 @@ class YamlParser(object):
|
||||||
|
|
||||||
for values in itertools.product(*dimensions):
|
for values in itertools.product(*dimensions):
|
||||||
params = copy.deepcopy(project)
|
params = copy.deepcopy(project)
|
||||||
|
params['template-name'] = VerbatimString(template_name)
|
||||||
params = self._applyDefaults(params, template)
|
params = self._applyDefaults(params, template)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -387,7 +388,6 @@ class YamlParser(object):
|
||||||
if key not in params:
|
if key not in params:
|
||||||
params[key] = template[key]
|
params[key] = template[key]
|
||||||
|
|
||||||
params['template-name'] = template_name
|
|
||||||
try:
|
try:
|
||||||
expanded = deep_format(
|
expanded = deep_format(
|
||||||
template, params,
|
template, params,
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<project>
|
<project>
|
||||||
<actions/>
|
<actions/>
|
||||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
<description>JJB template: complete001_{version}
|
||||||
|
<!-- Managed by Jenkins Job Builder --></description>
|
||||||
<keepDependencies>false</keepDependencies>
|
<keepDependencies>false</keepDependencies>
|
||||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
- defaults:
|
||||||
|
name: global
|
||||||
|
description: |
|
||||||
|
JJB template: {template-name}
|
||||||
|
|
||||||
- wrapper:
|
- wrapper:
|
||||||
name: timeout-wrapper
|
name: timeout-wrapper
|
||||||
wrappers:
|
wrappers:
|
||||||
|
@ -85,10 +90,11 @@
|
||||||
version:
|
version:
|
||||||
- 1.2
|
- 1.2
|
||||||
jobs:
|
jobs:
|
||||||
- 'complete001_{version}'
|
- 'complete001'
|
||||||
|
|
||||||
- job-template:
|
- job-template:
|
||||||
name: 'complete001_{version}'
|
name: 'complete001_{version}'
|
||||||
|
id: 'complete001'
|
||||||
scm:
|
scm:
|
||||||
- gerrit-scm:
|
- gerrit-scm:
|
||||||
project_pattern: openstack-infra/jenkins-job-builder
|
project_pattern: openstack-infra/jenkins-job-builder
|
||||||
|
|
Loading…
Reference in New Issue