diff --git a/jenkins_jobs/local_yaml.py b/jenkins_jobs/local_yaml.py
index cece2eadb..e1b26bd1c 100644
--- a/jenkins_jobs/local_yaml.py
+++ b/jenkins_jobs/local_yaml.py
@@ -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"""
diff --git a/tests/yamlparser/fixtures/jinja-yaml04-deepcopy.xml b/tests/yamlparser/fixtures/jinja-yaml04-deepcopy.xml
new file mode 100644
index 000000000..2cbd4fafd
--- /dev/null
+++ b/tests/yamlparser/fixtures/jinja-yaml04-deepcopy.xml
@@ -0,0 +1,38 @@
+
+
+
+ <!-- Managed by Jenkins Job Builder -->
+ false
+ false
+ false
+ false
+ true
+
+
+
+
+ echo "['repo-1', 'repo-2', 'repo-a1', 'repo-a2']"
+
+
+
+
+
+
+
+
+ <!-- Managed by Jenkins Job Builder -->
+ false
+ false
+ false
+ false
+ true
+
+
+
+
+ echo "['repo-1', 'repo-2', 'repo-b1', 'repo-b2']"
+
+
+
+
+
diff --git a/tests/yamlparser/fixtures/jinja-yaml04-deepcopy.yaml b/tests/yamlparser/fixtures/jinja-yaml04-deepcopy.yaml
new file mode 100644
index 000000000..17a91a31e
--- /dev/null
+++ b/tests/yamlparser/fixtures/jinja-yaml04-deepcopy.yaml
@@ -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