jenkins-job-builder/tests/localyaml/fixtures/custom_retain_anchors_j2_yaml.yaml
Adam Romanek aa5d6a538d Fix retaining anchors when using with !j2-yaml
Before this change using an anchor/alias in !j2-yaml resulted in an
exception, even if retain_anchors was set to True:

>      File "(...)/jenkins-job-builder/.tox/py38/lib/python3.8/site-packages/yaml/composer.py", line 68, in compose_node
>    raise ComposerError(None, None, "found undefined alias %r"
>    yaml.composer.ComposerError: found undefined alias '<alias-name-xxx>'

The reason was that LateYamlLoader.get_object_to_format() was calling
load() without retain_anchors=True so effectively it was resetting
anchors during deep formatting...

From now on yaml.load() is called directly to avoid unwanted
side-effects of load() which is meant to be called from other modules,
typically by parser.YamlParser().

Change-Id: I0fde43c5c27ddf78f18dc244d8dba5bd768306b7
2021-04-01 14:57:55 +02:00

13 lines
239 B
YAML

- job-template:
name: 'test-job-template'
builders:
- shell:
docker run {docker-image}
- project:
name: test-project
jobs:
- 'test-job-template':
docker-image: !j2-yaml: |
*docker-image