Skip to content

Add missing keywords to CI schema

Mireya Andres requested to merge add-ci-schema-keywords into master

What does this MR do and why?

For #218473 (closed)

This adds the missing keywords in our Gitlab CI schema. With this change, the pipeline editor will be able to lint the following rules:

Screenshots or screen recordings

Rule Recording Notes
When to save the cache cache:when Documentation
Trigger child pipeline with files from another project trigger recording Documentation. According to this discussion, file is required when project is given. ref is optional
Rules in include rules:include Documentation. The docs mention that you can only use certain variables for include:rules:if but enforcing this is beyond the scope of the linter/json schema

How to set up and validate locally

  1. Enable the :schema_linting feature flag. (rails c then Feature.enable(:schema_linting))

  2. Visit to the pipeline editor by going to CI/CD > Editor

  3. You can copy paste the following sample .gitlab-ci.yml content. The comments denote where the linter should complain about errors.

    There should also be a squiggly line underneath the keywords that have errors. You can hover on these to get more information on how to fix them. Fixing these errors should remove the linter complaints. You may also refer to the links above to read more on the rules the linter is enforcing.

include:
  - local: builds.yml
    rules: # this whole section should pass
      - if: '$INCLUDE_BUILDS == "true"'
        when: always

stages:
  - prepare

prepare_job:
  stage: prepare
  script:
    - echo 'running prepare_job'
  cache:
    when: 0 # error: should be a one of "on_success", "on_failure", "always"

child-pipeline:
  stage: prepare
  trigger:
    include:
      - project: 'my-group/my-pipeline-library' # error: missing 'file' property
      # should not complain if you add the optional `ref` property

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Mireya Andres

Merge request reports