diff options
author | Philip Roche <phil.roche@canonical.com> | 2019-07-12 16:15:26 +0100 |
---|---|---|
committer | Philip Roche <phil.roche@canonical.com> | 2019-07-12 17:58:40 +0100 |
commit | a9e12ed4a9f5866da0af5fdc68f60b09ca8efa4b (patch) | |
tree | aca165d3d8052c20441c1be7ca97515e51596b13 /tests | |
parent | 5d15fe76314976f54572f35292de4a8b85c778e9 (diff) | |
download | python-jenkins-job-builder-a9e12ed4a9f5866da0af5fdc68f60b09ca8efa4b.tar.gz python-jenkins-job-builder-a9e12ed4a9f5866da0af5fdc68f60b09ca8efa4b.tar.xz python-jenkins-job-builder-a9e12ed4a9f5866da0af5fdc68f60b09ca8efa4b.zip |
Add support for rendering jinja template as yaml
This also adds support for using custom loaders in job definitions
not just job-templates and builders. I have also added unit tests for include-jinja2-as-yaml custom loader.
Example usage:
- axis:
type: user-defined
name: VERSIONS
values:
!include-jinja2-as-yaml: versions.j2.yaml.inc
Where versions.j2.yaml.inc is
{% for possible_versions in configuration["possible_versions"] %}
- {{ possible_versions["versions"] }}
{% endfor -%}
Change-Id: I15a431d5a86b29d704efda8576965ade2b7dcd2f
Diffstat (limited to 'tests')
3 files changed, 41 insertions, 0 deletions
diff --git a/tests/yamlparser/fixtures/jinja-as-yaml-include01.xml b/tests/yamlparser/fixtures/jinja-as-yaml-include01.xml new file mode 100644 index 00000000..732bb2c4 --- /dev/null +++ b/tests/yamlparser/fixtures/jinja-as-yaml-include01.xml @@ -0,0 +1,31 @@ +<?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> + <hudson.model.ParametersDefinitionProperty> + <parameterDefinitions> + <hudson.model.ChoiceParameterDefinition> + <name>TEST_CHOICE</name> + <description/> + <choices class="java.util.Arrays$ArrayList"> + <a class="string-array"> + <string>a</string> + <string>b</string> + <string>c</string> + </a> + </choices> + </hudson.model.ChoiceParameterDefinition> + </parameterDefinitions> + </hudson.model.ParametersDefinitionProperty> + </properties> + <scm class="hudson.scm.NullSCM"/> + <builders/> + <publishers/> + <buildWrappers/> +</project> diff --git a/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml b/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml new file mode 100644 index 00000000..2ea430f0 --- /dev/null +++ b/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml @@ -0,0 +1,7 @@ +- job: + name: test-job-as-yaml + parameters: + - choice: + name: TEST_CHOICE + choices: + !include-jinja2-as-yaml: jinja-as-yaml-include01.yaml.inc diff --git a/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml.inc b/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml.inc new file mode 100644 index 00000000..c1c3c8b3 --- /dev/null +++ b/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml.inc @@ -0,0 +1,3 @@ +{% for item in ['a', 'b', 'c'] %} +- {{ item }} +{% endfor -%} |