Merge "Allow inclusion of multiple files"
This commit is contained in:
commit
a3aef64855
@ -75,6 +75,19 @@ Example:
|
||||
.. literalinclude::
|
||||
/../../tests/localyaml/fixtures/include-raw001-vars.sh
|
||||
|
||||
|
||||
Variants for the raw include tags ``!include-raw:`` and
|
||||
``!include-raw-escape:`` accept a list of files. All of the specified files
|
||||
are concatenated and included as string data.
|
||||
|
||||
Example:
|
||||
|
||||
.. literalinclude::
|
||||
/../../tests/localyaml/fixtures/include-raw-multi001.yaml
|
||||
|
||||
.. literalinclude::
|
||||
/../../tests/localyaml/fixtures/include-raw-escaped-multi001.yaml
|
||||
|
||||
"""
|
||||
|
||||
import codecs
|
||||
@ -205,6 +218,9 @@ class LocalLoader(OrderedConstructor, LocalAnchorLoader):
|
||||
self.add_constructor('!include-raw', self._include_raw_tag)
|
||||
self.add_constructor('!include-raw-escape',
|
||||
self._include_raw_escape_tag)
|
||||
self.add_constructor('!include-raw:', self._include_raw_tag_multi)
|
||||
self.add_constructor('!include-raw-escape:',
|
||||
self._include_raw_escape_tag_multi)
|
||||
|
||||
# constructor to preserve order of maps and ensure that the order of
|
||||
# keys returned is consistent across multiple python versions
|
||||
@ -244,9 +260,22 @@ class LocalLoader(OrderedConstructor, LocalAnchorLoader):
|
||||
raise
|
||||
return data
|
||||
|
||||
def _include_raw_tag_multi(self, loader, node):
|
||||
if not isinstance(node, yaml.SequenceNode):
|
||||
raise yaml.constructor.ConstructorError(
|
||||
None, None,
|
||||
"expected a sequence node, but found %s" % node.id,
|
||||
node.start_mark)
|
||||
|
||||
return '\n'.join(self._include_raw_tag(loader, scalar_node)
|
||||
for scalar_node in node.value)
|
||||
|
||||
def _include_raw_escape_tag(self, loader, node):
|
||||
return self._escape(self._include_raw_tag(loader, node))
|
||||
|
||||
def _include_raw_escape_tag_multi(self, loader, node):
|
||||
return self._escape(self._include_raw_tag_multi(loader, node))
|
||||
|
||||
def _escape(self, data):
|
||||
return re.sub(r'({|})', r'\1\1', data)
|
||||
|
||||
|
21
tests/localyaml/fixtures/include-raw-escaped-multi001.json
Normal file
21
tests/localyaml/fixtures/include-raw-escaped-multi001.json
Normal file
@ -0,0 +1,21 @@
|
||||
[
|
||||
{
|
||||
"template-job": {
|
||||
"name": "test-job-include-raw-{num}",
|
||||
"builders": [
|
||||
{
|
||||
"shell": "#!/bin/bash\n#\n# Sample script showing how the yaml include-raw tag can be used\n# to inline scripts that are maintained outside of the jenkins\n# job yaml configuration.\n\necho \"hello world\"\n\nexit 0\n\n#!/bin/bash\n#\n# sample script to check that brackets aren't escaped\n# when using the include-raw application yaml tag\n\nVAR1=\"hello\"\nVAR2=\"world\"\nVAR3=\"${{VAR1}} ${{VAR2}}\"\n\n[[ -n \"${{VAR3}}\" ]] && {{\n # this next section is executed as one\n echo \"${{VAR3}}\"\n exit 0\n}}\n\n"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"project": {
|
||||
"name": "test-job-template-1",
|
||||
"num": 1,
|
||||
"jobs": [
|
||||
"test-job-include-raw-{num}"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
13
tests/localyaml/fixtures/include-raw-escaped-multi001.yaml
Normal file
13
tests/localyaml/fixtures/include-raw-escaped-multi001.yaml
Normal file
@ -0,0 +1,13 @@
|
||||
- template-job:
|
||||
name: test-job-include-raw-{num}
|
||||
builders:
|
||||
- shell:
|
||||
!include-raw-escape:
|
||||
- include-raw001-hello-world.sh
|
||||
- include-raw001-vars.sh
|
||||
|
||||
- project:
|
||||
name: test-job-template-1
|
||||
num: 1
|
||||
jobs:
|
||||
- 'test-job-include-raw-{num}'
|
12
tests/localyaml/fixtures/include-raw-multi001.json
Normal file
12
tests/localyaml/fixtures/include-raw-multi001.json
Normal file
@ -0,0 +1,12 @@
|
||||
[
|
||||
{
|
||||
"job": {
|
||||
"name": "test-job-include-raw-1",
|
||||
"builders": [
|
||||
{
|
||||
"shell": "#!/bin/bash\n#\n# Sample script showing how the yaml include-raw tag can be used\n# to inline scripts that are maintained outside of the jenkins\n# job yaml configuration.\n\necho \"hello world\"\n\nexit 0\n\n#!/bin/bash\n#\n# sample script to check that brackets aren't escaped\n# when using the include-raw application yaml tag\n\nVAR1=\"hello\"\nVAR2=\"world\"\nVAR3=\"${VAR1} ${VAR2}\"\n\n[[ -n \"${VAR3}\" ]] && {\n # this next section is executed as one\n echo \"${VAR3}\"\n exit 0\n}\n\n"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
7
tests/localyaml/fixtures/include-raw-multi001.yaml
Normal file
7
tests/localyaml/fixtures/include-raw-multi001.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
- job:
|
||||
name: test-job-include-raw-1
|
||||
builders:
|
||||
- shell:
|
||||
!include-raw:
|
||||
- include-raw001-hello-world.sh
|
||||
- include-raw001-vars.sh
|
Loading…
x
Reference in New Issue
Block a user