YAML anchors for scripts do not work properly with includes

I have all my scripts in a file scripts-ci.yaml that I include in the main gitlab-ci.yaml .

When I try to use the scripts in scripts-ci.yaml from the main gitlab-ci.yml using include , I get the following error Included file .gitlab-ci.yml does not have valid YAML syntax! .

I should note that when I copy the script in gitlab-ci.yml directly and skip using include everything works fine.

Here is how things look:

# scripts.yaml
.test-include-scripts: &test-include-scripts
  - echo "testing includes with anchor scripts"
# .gitlab-ci.yml
include:
  - local: '.gitlab/ci/scripts-ci.yaml'
test-include:
  script:
    - *test-include-scripts

You can see an example here:

1 Like

It is not a bug! The problem is solved thanks to Dov Hershkovitch :ok_hand::ok_hand:

You can’t use YAML anchors across different YAML files sourced by include . You can only refer to anchors in the same file. To reuse configuration from different YAML files, use !reference tags or the extends keyword.

1 Like