Skip to content

Allow YAML `null` value for `only` and `except` filters

What does this MR do and why?

Extends the json-schema of .gitlab-ci.yml files to allow null type values for job:only and job:except fields. In the scenario that a job extends another job or template it is possible to clear the extended job's only or except field by leaving their values blank (setting them as a null type).

This also is permitted by the output of gitlab's CI/CD editor, see screenshot 1.

IDE's using the published schema (e.g. PhpStorm, see screenshot 2) show a warning for this declaration as it violates the schema. This merge requests adds null as an acceptable value for the type definition filter which is only referenced for the only and except fields of job templates.

Describe in detail what your merge request does and why.

Adds { type: null } to the one-of block that makes the filter definition. This adds null as an accepted value to only and except keys on job definitions.

Screenshots or screen recordings

Screenshot 1 - Gitlab parses null in the only and except fields

image

Screenshot 2 - PhpStorm rejects null values for only and except fields

image

How to set up and validate locally

  1. Goto CI/CD editor to validate the snippet below
  2. Validate the snippet against the updated schema

The snippet:

deploy-template:
  script:
    - echo "hello world"
  only:
    - foo
  except:
    - bar

deploy-without-only:
  extends: deploy-template
  only:

deploy-without-except:
  extends: deploy-template
  except:

The snippet ought to render to the following merged output:

---
deploy-template:
  script:
  - echo "hello world"
  only:
  - foo
  except:
  - bar
deploy-without-only:
  script:
  - echo "hello world"
  only: 
  except:
  - bar
  extends: deploy-template
deploy-without-except:
  script:
  - echo "hello world"
  only:
  - foo
  except: 
  extends: deploy-template

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