!reference merging script array items looks odd in merged YAML view in pipeline editor
Summary
Referencing a script
attribute with one or more array elements inside leads into a valid and working config, though the merged YAML view does not show the final merged array items. Instead, you'll get the referenced array object as new job script array item, a nested object-in-object view so to speak.
- (- script1 script2 script3)
- scriptcmd
Depending on the programming language involved, this may lead to different results. Developers who investigate this may wonder what happened here. The merged array items should be presented instead.
Steps to reproduce
- New project +
CI/CD > Pipeline Editor
- Use the following snippet to reproduce the error
stages:
- lint
- test
.python-req:
script:
- pip install pyflakes
lint-python:
extends: .python-req
stage: lint
image: python:latest
script:
- !reference [.python-req, script]
- pyflakes python/
Example Project
What is the current bug behavior?
!reference
merges both script
sections accordingly, and the configured pipeline runs as excepted. The odd thing is that the View Merged YAML
tab prints
stages:
- ".pre"
- lint
- test
- ".post"
".python-req":
script:
- pip install pyflakes
lint-python:
script:
- - pip install pyflakes
- pyflakes python/
extends: ".python-req"
stage: lint
image: python:latest
This gets worse when you reference more than 1 array element, e.g.
.python-req:
script:
- pip install -r python/requirements.txt
- pip install pyflakes
lint-python:
extends: .python-req
stage: lint
image: python:latest
script:
- !reference [.python-req, script]
- pyflakes python/
gets merged into
stages:
- ".pre"
- lint
- test
- ".post"
".python-req":
script:
- pip install -r python/requirements.txt
- pip install pyflakes
lint-python:
script:
- - pip install -r python/requirements.txt
- pip install pyflakes
- pyflakes python/
extends: ".python-req"
stage: lint
image: python:latest
What is the expected correct behavior?
lint-python:
script:
- pip install pyflakes
- pyflakes python/
Relevant logs and/or screenshots
From the second example with multiple script
entries referenced.
Possible fixes
Probably the merged script
array is processed later correctly, and the returned value for the merged yaml is just off in that regard. Or we are using a Ruby/Go type method to merge arrays automatically at some point, without controlling it ourselves.
The array merger result is what the merged YAML view (and API endpoint) need to provide.