1

Hey I am looking for a YAML validator to verify my .yaml files are correct. I am using GitLab CI. Since I have a massive configuration I split it to several yaml files and import them on my main yaml file (using gitlab's CI syntax for import .yml files)

For example in main.yml I have:

include:
    - ".imported_config1.yml"
    - ".imported_config2.yml"

There are many yaml validators online, but none seem to validate it with the imports and it takes time and effort to manually copy paste all the imports to a different file and validate it just for the validation process...

When I run GitLab CI it verifies the .yaml correctly, but I am looking for an external tool to perform only the validation process before the config file is in the server.

Is there any tool or fix for this?

1
  • You may want to add more context to the question: this is a GitLab CI configuration and whether you have tried the pipeline editor or the VS Code extension marketplace.visualstudio.com/…
    – Kariem
    Commented Jul 22, 2022 at 10:45

1 Answer 1

1

From what I understand, there is no standard mechanism in YAML to import/include other files (see also this answer on SO and associated discussion). So, you will either need to follow a standard format that already provides this, such as OpenAPI's $ref, or use a validator that has a proper handler for this include node.

Looking through the linked discussion on SO, there seems to be a way to use inheritance via the Ruby Gem yaml_extend and PyYAML can support something like !include which seems to be what you are looking for.

3
  • Hey thanks for the answer! The include infrastructure I use is Gitlab CI's. docs.gitlab.com/ee/ci/yaml I want to have an external validator that can handle that...
    – Or b
    Commented Jul 21, 2022 at 14:04
  • @Orb I could not verify this, but the documentation says the pipeline editor should be capable of verifying this and also, there is a VS Code extension: marketplace.visualstudio.com/… - Does this work for you?
    – Kariem
    Commented Jul 22, 2022 at 10:43
  • 1
    Thanks for the notes mate. I edited the question. GitLab CI does verify it although I am looking for an external tool to perform the check before the files are in the server (e.g. using pre-commit hook). I use VS2015 and not VScode although the extension you mentioned seem to have what I am looking for.. I saw that there is an extension for VS I will check it out. marketplace.visualstudio.com/…
    – Or b
    Commented Jul 23, 2022 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.