Fix !include parsing with variable

Do not overwrite template string when parsing yaml.

Story: 2000996
Change-Id: Id1b12be69c3994fa4108a9841c0128da9dc883ef
This commit is contained in:
Aleksandr Charykov 2017-04-19 16:11:12 +02:00 committed by Darragh Bailey
parent 870045688b
commit 50fd0d2833
3 changed files with 82 additions and 2 deletions

View File

@ -433,8 +433,10 @@ class LazyLoader(object):
return "%s %s" % (self._cls.yaml_tag, self._node.value)
def format(self, *args, **kwargs):
self._node.value = self._node.value.format(*args, **kwargs)
return self._cls.from_yaml(self._loader, self._node)
node = yaml.ScalarNode(
tag=self._node.tag,
value=self._node.value.format(*args, **kwargs))
return self._cls.from_yaml(self._loader, node)
def load(stream, **kwargs):

View File

@ -0,0 +1,65 @@
<?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>#!/bin/bash
#
# version 1.1 of the echo vars script
MSG=&quot;hello world&quot;
VERSION=&quot;1.1&quot;
[[ -n &quot;${MSG}&quot; ]] &amp;&amp; {
# this next section is executed as one
echo &quot;${MSG}&quot;
echo &quot;version: ${VERSION}&quot;
exit 0
}
</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>#!/bin/bash
#
# version 1.2 of the echo vars script
MSG=&quot;hello world&quot;
VERSION=&quot;1.2&quot;
[[ -n &quot;${MSG}&quot; ]] &amp;&amp; {
# this next section is executed as one
echo &quot;${MSG}&quot;
echo &quot;version: ${VERSION}&quot;
exit 0
}
</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers/>
</project>

View File

@ -0,0 +1,13 @@
- job-template:
name: "test-job-{job_name}"
builders:
- shell:
!include-raw: 'lazy-load-scripts/echo_vars_{job_name}.sh'
- project:
name: 'test-project'
job_name:
- 1.1
- 1.2
jobs:
- "test-job-{job_name}"