Skip to content

unknown anchor error when merging multiple files #1564

Answered by mikefarah
chr1shung asked this question in Q&A
Discussion options

You must be logged in to vote

The issue is that the merge result has x-advance-env-variables at the bottom of the yaml file, which isn't valid (need to define anchors before you use them). This is because yq isn't smart enough to pull it up to the top - when merging files, it will take the 2nd file and merge into the 1st. New map keys get added to the bottom.

There are two options to fix it:

a) add an empty x-advance-env-variables to the first file (or, better, generic variables map that all variables get merged into). Nice thing about a 'variables' map in the first file is you don't need knowledge of 'x-advance-env-variables' outside of advance.yml.

or b) manually re-order the map after the merge like so:

yq ea '. as…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@chr1shung
Comment options

Answer selected by chr1shung
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants