Merge "Fix support for !j2-yaml tag on project level (missing deepcopy impl)"

This commit is contained in:
Zuul 2021-02-15 19:53:00 +00:00 committed by Gerrit Code Review
commit 08d69a6594
3 changed files with 72 additions and 0 deletions

View File

@ -609,6 +609,9 @@ class LateYamlLoader(CustomLoader):
self._yaml_str = yaml_str
self._loader = loader
def __deepcopy__(self, memo):
return LateYamlLoader(self._yaml_str, copy.deepcopy(self._loader, memo))
def get_object_to_format(self):
return load(self._yaml_str, search_path=self._loader._search_path)
@ -618,6 +621,9 @@ class Jinja2YamlLoader(Jinja2Loader):
yaml_str = super(Jinja2YamlLoader, self).format(**kwargs)
return LateYamlLoader(yaml_str, self)
def __deepcopy__(self, memo):
return Jinja2YamlLoader(self._contents, self._search_path)
class CustomLoaderCollection(object):
"""Helper class to format a collection of CustomLoader objects"""

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</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 &quot;['repo-1', 'repo-2', 'repo-a1', 'repo-a2']&quot;</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers/>
</project>
<?xml version="1.0" encoding="utf-8"?>
<project>
<actions/>
<description>&lt;!-- Managed by Jenkins Job Builder --&gt;</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 &quot;['repo-1', 'repo-2', 'repo-b1', 'repo-b2']&quot;</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers/>
</project>

View File

@ -0,0 +1,28 @@
- job-template:
name: 'test-job-template-{variant}'
builders:
- shell:
echo "{repos}"
- project:
name: test-project
repos_common:
- repo-1
- repo-2
jobs:
- 'test-job-template-{variant}':
variant: 'a'
repos: !j2-yaml: |
{% for repo in repos_common %}
- {{ repo }}
{% endfor %}
- repo-a1
- repo-a2
- 'test-job-template-{variant}':
variant: 'b'
repos: !j2-yaml: |
{% for repo in repos_common %}
- {{ repo }}
{% endfor %}
- repo-b1
- repo-b2