summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jenkins_jobs/local_yaml.py9
-rw-r--r--tests/yamlparser/fixtures/jinja-include01.xml23
-rw-r--r--tests/yamlparser/fixtures/jinja-include01.yaml15
-rw-r--r--tests/yamlparser/fixtures/jinja-include01.yaml.inc1
-rw-r--r--tests/yamlparser/fixtures/jinja-include02.xml23
-rw-r--r--tests/yamlparser/fixtures/jinja-include02.yaml14
6 files changed, 82 insertions, 3 deletions
diff --git a/jenkins_jobs/local_yaml.py b/jenkins_jobs/local_yaml.py
index 2ef39ffd..c49393d6 100644
--- a/jenkins_jobs/local_yaml.py
+++ b/jenkins_jobs/local_yaml.py
@@ -324,7 +324,7 @@ class J2String(BaseYAMLObject):
@classmethod
def from_yaml(cls, loader, node):
- return Jinja2Loader(node.value)
+ return Jinja2Loader(node.value, loader.search_path)
class YamlInclude(BaseYAMLObject):
@@ -423,7 +423,7 @@ class YamlIncludeJinja2(YamlIncludeRaw):
contents = cls._open_file(loader, node)
if isinstance(contents, LazyLoader):
return contents
- return Jinja2Loader(contents)
+ return Jinja2Loader(contents, loader.search_path)
class DeprecatedTag(BaseYAMLObject):
@@ -456,9 +456,12 @@ class CustomLoader(object):
class Jinja2Loader(CustomLoader):
"""A loader for Jinja2-templated files."""
- def __init__(self, contents):
+
+ def __init__(self, contents, search_path):
self._template = jinja2.Template(contents)
self._template.environment.undefined = jinja2.StrictUndefined
+ self._template.environment.loader = jinja2.FileSystemLoader(
+ search_path)
def format(self, **kwargs):
return self._template.render(kwargs)
diff --git a/tests/yamlparser/fixtures/jinja-include01.xml b/tests/yamlparser/fixtures/jinja-include01.xml
new file mode 100644
index 00000000..de5ed018
--- /dev/null
+++ b/tests/yamlparser/fixtures/jinja-include01.xml
@@ -0,0 +1,23 @@
+<?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>test variable
+a
+b
+c
+</command>
+ </hudson.tasks.Shell>
+ </builders>
+ <publishers/>
+ <buildWrappers/>
+</project>
diff --git a/tests/yamlparser/fixtures/jinja-include01.yaml b/tests/yamlparser/fixtures/jinja-include01.yaml
new file mode 100644
index 00000000..c64bf778
--- /dev/null
+++ b/tests/yamlparser/fixtures/jinja-include01.yaml
@@ -0,0 +1,15 @@
+- builder:
+ name: test-builder
+ builders:
+ - shell:
+ !include-jinja2: jinja-include01.yaml.inc
+
+- job:
+ name: test-job
+ builders:
+ - test-builder:
+ var: "test variable"
+ test_list:
+ - a
+ - b
+ - c
diff --git a/tests/yamlparser/fixtures/jinja-include01.yaml.inc b/tests/yamlparser/fixtures/jinja-include01.yaml.inc
new file mode 100644
index 00000000..7fbaa1cb
--- /dev/null
+++ b/tests/yamlparser/fixtures/jinja-include01.yaml.inc
@@ -0,0 +1 @@
+{% include 'jinja01.yaml.inc' %}
diff --git a/tests/yamlparser/fixtures/jinja-include02.xml b/tests/yamlparser/fixtures/jinja-include02.xml
new file mode 100644
index 00000000..de5ed018
--- /dev/null
+++ b/tests/yamlparser/fixtures/jinja-include02.xml
@@ -0,0 +1,23 @@
+<?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>test variable
+a
+b
+c
+</command>
+ </hudson.tasks.Shell>
+ </builders>
+ <publishers/>
+ <buildWrappers/>
+</project>
diff --git a/tests/yamlparser/fixtures/jinja-include02.yaml b/tests/yamlparser/fixtures/jinja-include02.yaml
new file mode 100644
index 00000000..25a43d50
--- /dev/null
+++ b/tests/yamlparser/fixtures/jinja-include02.yaml
@@ -0,0 +1,14 @@
+- builder:
+ name: test-builder
+ builders:
+ - shell: !j2: "{% include 'jinja01.yaml.inc' %}"
+
+- job:
+ name: test-job
+ builders:
+ - test-builder:
+ var: "test variable"
+ test_list:
+ - a
+ - b
+ - c