Story 2011112: include-raw-verbatim fails on job-template

don't expand IncludeRawVerbatim twice

> FAILED tests/loader/test_loader.py::test_include_job[include002] - jenkins_jobs.errors.JenkinsJobsException: While formatting string "#!/bin/bash\n#\n# sample script to check that variables aren't expanded\n# when usi...": Missing parameter: 'VAR1'
> FAILED tests/loader/test_loader.py::test_include[include002] - jenkins_jobs.errors.JenkinsJobsException: While formatting string "#!/bin/bash\n#\n# sample script to check that variables aren't expanded\n# when usi...": Missing parameter: 'VAR1'

Change-Id: I88b22987eabe99f00d99755299256d4aba8a1c76
This commit is contained in:
Victor Seva 2024-04-15 16:34:30 +02:00
parent 9c38f33a4b
commit 4897d5e047
6 changed files with 62 additions and 4 deletions

View File

@ -143,12 +143,13 @@ class Expander:
# Expand only yaml objects.
class YamlObjectsExpander(Expander):
def __init__(self):
super().__init__()
def __init__(self, config=None):
super().__init__(config)
self.expanders.update(
{
str: dont_expand,
LocString: dont_expand,
IncludeRawVerbatim: dont_expand,
}
)

View File

@ -18,7 +18,7 @@ from functools import partial
from .errors import JenkinsJobsException
from .loc_loader import LocLoader
from .yaml_objects import BaseYamlObject
from .expander import Expander, deprecated_yaml_tags, yaml_classes_list
from .expander import YamlObjectsExpander, deprecated_yaml_tags, yaml_classes_list
from .roots import root_adders
logger = logging.getLogger(__name__)
@ -118,7 +118,7 @@ def enum_expanded_paths(path_list):
def load_files(config, roots, path_list):
expander = Expander(config)
expander = YamlObjectsExpander(config)
loader = Loader.empty(config)
for path in enum_expanded_paths(path_list):
if is_stdin(path):

View File

@ -0,0 +1,14 @@
#!/bin/bash
#
# sample script to check that variables aren't expanded
# when using the !include-raw-verbatim: application yaml tag
VAR1="hello"
VAR2="world"
VAR3="${VAR1} ${VAR2}"
[[ -n "${VAR3}" ]] && {
# this next section is executed as one
echo "${VAR3}"
exit 0
}

View File

@ -0,0 +1,33 @@
<?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
#
# sample script to check that variables aren't expanded
# when using the !include-raw-verbatim: application yaml tag
VAR1=&quot;hello&quot;
VAR2=&quot;world&quot;
VAR3=&quot;${VAR1} ${VAR2}&quot;
[[ -n &quot;${VAR3}&quot; ]] &amp;&amp; {
# this next section is executed as one
echo &quot;${VAR3}&quot;
exit 0
}
</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers/>
</project>

View File

@ -0,0 +1,6 @@
# using !include in job-template
- job-template: !include: include002.yaml.inc
- project:
name: acc-cdi
jobs:
- test-gerrit

View File

@ -0,0 +1,4 @@
name: test-gerrit
builders:
- shell:
!include-raw-verbatim: include-raw-vars.sh