zeitbach.com

Inputs for GitLab CI/CD configuration files

TIL: Since GitLab 17.0, we can define input parameters on reusable CI/CD config files.

The parameters are defined under spec:inputs. Here is an example:

spec:
  inputs:
    version:
      description: "Regex-validated version string with default"
      type: string
      default: "v17.0"
      regex: ^v\d+\.\d+(\.\d+)?$
---

Note the dashes at the end. They are necessary because spec is a header keyword that must appear in the header section at the top of the file, separated by three dashes.

When including a config file, we can pass values to the defined inputs under include:inputs.

include:
  - project: "path/to/another/project"
    ref: master
    file: "path/to/config/file.yml"
    inputs:
      version: "v18.0"

This is quite useful and much nicer than hard-coded global variables.