Fix double inderection of name templates
Ensure that we can resolve any lazily loaded templates that might be dictionary keys in yaml. For more informmation please see the added test case in tests/yamlparser/fixtures/jinja-string04.yaml. Change-Id: I67fbca422f2165729af15e4d039278ad66f6240b Story: 2006431 Task: 36338
This commit is contained in:
parent
b27399c477
commit
8c19ca0cd2
@ -59,9 +59,9 @@ def deep_format(obj, paramdict, allow_empty=False):
|
||||
ret = type(obj)()
|
||||
for item in obj:
|
||||
try:
|
||||
ret[
|
||||
CustomFormatter(allow_empty).format(item, **paramdict)
|
||||
] = deep_format(obj[item], paramdict, allow_empty)
|
||||
ret[deep_format(item, paramdict, allow_empty)] = deep_format(
|
||||
obj[item], paramdict, allow_empty
|
||||
)
|
||||
except KeyError as exc:
|
||||
missing_key = exc.args[0]
|
||||
desc = "%s parameter missing to format %s\nGiven:\n%s" % (
|
||||
|
19
tests/yamlparser/fixtures/jinja-string04.xml
Normal file
19
tests/yamlparser/fixtures/jinja-string04.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?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>123</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
40
tests/yamlparser/fixtures/jinja-string04.yaml
Normal file
40
tests/yamlparser/fixtures/jinja-string04.yaml
Normal file
@ -0,0 +1,40 @@
|
||||
# Make sure Jinja subsittuions work from within "defaults"
|
||||
- defaults:
|
||||
name: test-defaults
|
||||
test_var:
|
||||
!j2: "{% for x in [1, 2, 3] %}{{ x }}{% endfor %}"
|
||||
use_test_builder: true
|
||||
test_builder_name:
|
||||
!j2: |
|
||||
{% if use_test_builder -%}
|
||||
test-shell-builder-alternate
|
||||
{%- else -%}
|
||||
test-shell-builder-default
|
||||
{%- endif %}
|
||||
|
||||
- project:
|
||||
name: test-proj
|
||||
jobs:
|
||||
- test-jobs-{argument}:
|
||||
argument:
|
||||
- 1
|
||||
|
||||
# This type of variable propagation only works in job templates.
|
||||
- job-template:
|
||||
name: test-jobs-{argument}
|
||||
defaults: test-defaults
|
||||
builders:
|
||||
# This fails because we only render the initial template, not the final template.
|
||||
- "{test_builder_name}":
|
||||
test_var: "{test_var}"
|
||||
|
||||
- builder:
|
||||
name: test-shell-builder-alternate
|
||||
builders:
|
||||
- shell: "{test_var}"
|
||||
|
||||
|
||||
- builder:
|
||||
name: test-shell-builder-default
|
||||
builders:
|
||||
- shell: "default"
|
Loading…
x
Reference in New Issue
Block a user