Do not report empty include expansion as invalid YAML

What does this MR do and why?

An included CI config file whose include: entries are all dropped by their include:rules: was reported as Included file '...' does not have valid YAML syntax! and persisted as a failed config_error. The YAML parsed fine — the file simply expanded to nothing.

Root cause

File::Base#validate_hash! checked to_hash, the result after expanding the file's own include: entries. A file containing only include: entries expands to {} once those entries are filtered out by their rules, so to_hash was blank and the file was flagged as malformed.

Fix

Emptiness after expansion is a filtering outcome, not a syntax problem. Check the file's own parsed content (content_result.content, before include expansion) instead. This is blank in exactly one case — the file parsed but contained no YAML document (e.g. empty or comments-only). That case still errors, but with an accurate message, since unparseable/non-hash input is already rejected earlier as Invalid configuration format:

Included file `blank.yml` contains no configuration!

The method is renamed to validate_parsed_content_presence! and shares a parsed_content_blank? predicate with expanded_content_hash.

Behaviour

Scenario Before After
Included file whose includes are all filtered by rules config_error (invalid YAML) no-op; sibling jobs run
Included file with no YAML document (empty / comments only) config_error (invalid YAML) config_error: "contains no configuration!"
Included file with a non-hash root (e.g. an array) config_error: "Invalid configuration format" unchanged
Included file defining config but no jobs (variables: only) resolves unchanged

How to reproduce

.gitlab-ci.yml includes wrapper.yml → includes component.yml → includes mr-only.yml gated by rules: [if: $CI_PIPELINE_SOURCE == "merge_request_event"]. On a push pipeline the innermost include is filtered out.

  • Before: Included file 'wrapper.yml' does not have valid YAML syntax!, persisted as a failed config_error
  • After: pipeline runs normally

Testing

  • Unit spec in file/base_spec.rb (comments-only file) and integration specs in external/processor_spec.rb (filtered-out includes, filtered vs matching, comments-only file)
  • Verified the bug-reproducing spec fails without the fix; RuboCop clean

No doc update needed: the message is not referenced in doc/ and CI config errors are not externalized for translation.

References

Edited by Oleg Yakovenko

Merge request reports

Loading
Loading