diff --git a/jenkins_jobs/expander.py b/jenkins_jobs/expander.py index 57ded06f8..fed2f51f3 100644 --- a/jenkins_jobs/expander.py +++ b/jenkins_jobs/expander.py @@ -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, } ) diff --git a/jenkins_jobs/loader.py b/jenkins_jobs/loader.py index 6ffded141..a79a26284 100644 --- a/jenkins_jobs/loader.py +++ b/jenkins_jobs/loader.py @@ -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): diff --git a/tests/yamlparser/job_fixtures/include-raw-vars.sh b/tests/yamlparser/job_fixtures/include-raw-vars.sh new file mode 100644 index 000000000..7cedeaed4 --- /dev/null +++ b/tests/yamlparser/job_fixtures/include-raw-vars.sh @@ -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 +} diff --git a/tests/yamlparser/job_fixtures/include002.xml b/tests/yamlparser/job_fixtures/include002.xml new file mode 100644 index 000000000..f341ef024 --- /dev/null +++ b/tests/yamlparser/job_fixtures/include002.xml @@ -0,0 +1,33 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + #!/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 +} + + + + + + diff --git a/tests/yamlparser/job_fixtures/include002.yaml b/tests/yamlparser/job_fixtures/include002.yaml new file mode 100644 index 000000000..6b1906a47 --- /dev/null +++ b/tests/yamlparser/job_fixtures/include002.yaml @@ -0,0 +1,6 @@ +# using !include in job-template +- job-template: !include: include002.yaml.inc +- project: + name: acc-cdi + jobs: + - test-gerrit diff --git a/tests/yamlparser/job_fixtures/include002.yaml.inc b/tests/yamlparser/job_fixtures/include002.yaml.inc new file mode 100644 index 000000000..e918fab21 --- /dev/null +++ b/tests/yamlparser/job_fixtures/include002.yaml.inc @@ -0,0 +1,4 @@ +name: test-gerrit +builders: + - shell: + !include-raw-verbatim: include-raw-vars.sh