Pipeline Inputs

For pipelines using spec: inputs:, pass values via CLI flags or a YAML file.

Usage#

glci run --input force_build=true --input runner_version=17.6.0
glci run --inputs-file inputs.yml
glci run --inputs-file defaults.yml --input force_build=true  # CLI overrides file
glci show --input force_build=true                            # works with show too
glci merged --input force_build=true                          # and with merged

Input types#

TypeAccepted valuesNormalization
stringAny valueNone
booleanA YAML boolean, or the text true or false. See Boolean inputsResolves to true/false
numberText (--input, or a quoted YAML value) is read by GitLab’s JSON parser: any number it reads counts, NaN and Infinity included, with surrounding whitespace allowed, while .5, Inf, 1.e3 and "0x1F" are refused. In YAML (default:, an include entry’s inputs:, --inputs-file, a trigger’s inputs:) an unquoted YAML 1.1 number counts as GitLab reads it: .5 is 0.5, .inf is Infinity, 0x1F is 31, 010 is 8, 1_000 is 1000 and 1:30 is 5400. A plain 1e3 is no YAML number, so it is read as text tooResolves to the number as Ruby prints it: 1e3 is 1000.0, 5.00 is 5.0, 007 is 7, +5 is 5 (see How values are substituted). A quoted or --input decimal written with more than 16 digits is a BigDecimal to GitLab, which prints it with all its significant digits; glci reads it as a float
arrayAny valueA list when the block is the whole value, its hash and list items intact; inside other text, the list as Ruby prints it, ["a", {:k=>"v"}], as GitLab writes it. Elements can be read with [N]; see Array elements

Boolean inputs#

A boolean input accepts the same values GitLab does, and every route applies the same rule. GitLab parses the value as JSON and keeps it only when the result is true or false. So a value passes in two cases:

Everything else fails with GitLab’s error, `flag` input: provided value is not a boolean. That includes a quoted "yes", "no", "on", "1", "0" or "TRUE", the integer 1, and --input flag=yes. A refused default fails with resolved default: `flag` input: default value is not a boolean, even when a supplied value overrides it, as on GitLab. For a value that reads as a boolean, such as yes, on, 1 or TRUE, glci adds ; write true or false to the message.

The same word therefore behaves differently in YAML and on the command line. flag: on in an inputs file is a boolean and passes, while --input flag=on is the text on and is refused, as GitLab refuses it from the API.

Where the value comes fromAcceptedRefused
YAML (default:, include inputs:, --inputs-file, trigger inputs:)true, false, unquoted yes/no/on/off in any case, "true", "false""yes", "on", "1", "TRUE", 1, 0, a list or a hash
--input, the TUI run formtrue, falseyes, on, 1, 0, TRUE, and an empty --input flag= unless the input takes its default from rules:

A boolean field left empty in the TUI run form supplies no value, so the input takes its default.

Inputs file format#

# inputs.yml
force_build: true
runner_version: "17.6.0"
environment: staging
deploy_rules:            # an array input, hash items included
  - if: $CI_COMMIT_BRANCH
    when: manual

The file must be a mapping of input names to values. Anything else, such as a list, fails with parsing inputs file: must be a mapping of input names to values. An empty file supplies no inputs.

A value reaches a boolean, number or array input as the same value would from an include entry’s inputs:. A list or a hash keeps its structure, and a float keeps the .0 Ruby prints (3.0). Two differences remain:

Conditional defaults with rules:#

An input can take its options and default from a rules: list instead of declaring them directly. Rules are evaluated in order and the first match wins; an entry with no if: is the fallback.

spec:
  inputs:
    environment:
      options: ['development', 'production']
      default: 'development'
    instance_type:
      rules:
        - if: $[[ inputs.environment ]] == 'development'
          options: ['small', 'medium']
          default: 'small'
        - if: $[[ inputs.environment ]] == 'production'
          options: ['large', 'xlarge']
          default: 'large'

A rule’s if: can only reference other inputs. CI/CD variables are not in scope, so a $CI_COMMIT_TAG written in an input rule is undefined whatever triggered the pipeline. Comparing an undefined value against "" is false, so a rule written that way never matches — and $CI_COMMIT_TAG == null is always true, so a rule written that way always matches. This is GitLab’s behaviour, which evaluates these rules with the inputs alone.

Inputs resolve in declaration order. A rule may reference another input, but only one declared before it will have a value — a reference to an input declared later sees nothing, not that input’s default, unless the caller supplied a value for it explicitly. That is how GitLab resolves them, and it is worth knowing because it looks like a bug:

spec:
  inputs:
    image:                          # declared first
      rules:
        - if: $[[ inputs.flavor ]] == 'slim'
          default: 'alpine'
        - default: 'debian'         # always taken: flavor has no value yet
    flavor:
      default: 'slim'

Swap the two entries and image resolves to alpine.

A rule may also name an input that does not exist, or two inputs may read each other. Neither is an error — GitLab accepts both, and so does glci: an unknown name is simply undefined, and a cycle cannot loop because each input resolves exactly once. The practical consequence is that a typo in an input reference is silent: the rule never matches and the fallback wins, with nothing reported. Check the resolved value with glci merged if a rule is not behaving.

Further rules, all matching GitLab:

Input definitions from other files (spec:include)#

A spec: header can load input definitions from other files with spec: include:, the same way GitLab does:

spec:
  include:
    - local: /shared-inputs.yml
    - project: my-group/shared-configs
      ref: main
      file: /ci/common-inputs.yml
    - remote: https://example.com/ci/shared-inputs.yml
  inputs:
    version:
      default: '1.0'
---
deploy:
  script: echo "$[[ inputs.environment ]] $[[ inputs.version ]]"
# shared-inputs.yml
inputs:
  environment:
    options: ['staging', 'production']
    default: staging

How values are substituted#

Blocks are substituted into the parsed YAML, as GitLab does, not into the raw file text:

Array elements#

A block can read one element of an array input with [N], counting from 0, and reach further into nested arrays and into hashes:

spec:
  inputs:
    arr:
      type: array
      default: [x, y, z]
    platforms:
      type: array
      default: [[amd64, arm64], {name: riscv, tags: [rv64]}]
---
job-$[[ inputs.arr[1] ]]:
  script:
    - echo $[[ inputs.arr[0] ]]
    - echo $[[ inputs.platforms[0][1] ]] $[[ inputs.platforms[1].name ]] $[[ inputs.platforms[1].tags[0] ]]

This makes one job, job-y, running echo x and echo arm64 riscv rv64.

AccessError
inputs.arr[3]array index 3 out of bounds (size: 3) in `inputs.arr[3]`
inputs.name[0] for a string, number or boolean input, or an index into an element that is not an arraycannot index into non-array value at [0] in `inputs.name[0]`
inputs.arr[-1], inputs.arr[a], inputs.arr[]invalid array index in `inputs.arr[-1]`: `-1` is not a valid index
inputs.arr[0, or a decimal such as inputs.arr[1.5] (the access splits on . first)invalid array index in `inputs.arr[0`: missing closing bracket
inputs.[0]invalid indexed access without a key in `inputs.[0]`
inputs[0].arrcannot index into non-array value at [0] in `inputs[0].arr`
inputs, aloneinvalid pattern used for interpolation. valid pattern is $[[ inputs.input ]]
inputs.arr[0]x, or inputs.my-list[0] for a name with a hypheninvalid array index syntax in `inputs.arr[0]x`
inputs.arr[0][0][0][0][0][0]too many array indices in `inputs.arr[0][0][0][0][0][0]` (maximum depth: 5)
inputs.arr.first, or a key a hash element lacksunknown interpolation provided: `first` in `inputs.arr.first`
an access longer than 1024 bytesmaximum interpolation expression size exceeded

An input name containing a hyphen can be used whole ($[[ inputs.my-list ]]) but not indexed, on GitLab or in glci. A block is closed by the first ]], so $[[ inputs.arr[0]]] reads as inputs.arr[0 followed by a ]: leave a space before the closing brackets.

Functions#

An interpolation block can pipe its value through up to three functions, applied in the order written:

spec:
  inputs:
    variant:
      default: '$IMAGE_FLAVOUR'
    runner_tags:
      default: 'docker, linux'
    message:
      default: "it's done"
---
.base::image-sha:
  image: example/img:sha

build:
  extends: .base::image-$[[ inputs.variant | expand_vars ]]
  tags: $[[ inputs.runner_tags | split(',') ]]
  script:
    - echo $[[ inputs.message | posix_escape ]]

Run with --env IMAGE_FLAVOUR=sha, build extends .base::image-sha, gets the docker and linux tags, and runs echo it\'s\ done.

FunctionResult
expand_varsExpands $VAR and ${VAR} references. A variable it cannot find is left as written.
truncate(<offset>,<length>)The length characters starting at offset; empty when offset is past the end.
posix_escapeThe value escaped for a POSIX shell, so it reaches the command as one word.
split('<separator>')A list: the value split on separator, each element trimmed, empty ones dropped. split(' ') splits on any run of whitespace. Inside other text the list reads as Ruby prints it, ["a", "b"].
CI configuration is invalid: parsing CI config: interpolating pipeline inputs: `$[[ inputs.message | upcase ]]`: no function matching `upcase`: check that the function name, arguments, and types are correct

A block is closed by the first ]], even one inside a quoted argument, so split(']]') is not a valid function on GitLab or in glci.

Validation#

glci validates inputs before starting the pipeline:

An included file or component whose inputs do not resolve fails the parse, naming the include it came from:

CI configuration is invalid: parsing CI config: resolving includes: include local "/ci/comp.yml": resolving inputs: required input "env" not provided

An include’s inputs come only from that include entry’s own inputs: map. --input and --inputs-file reach the root file’s spec: and nothing else, which is also how GitLab behaves.

The entry may supply only inputs the included file declares. An argument its spec: header does not declare, including every argument for a header that declares no inputs, fails the parse with GitLab’s error rather than being dropped while the input it was meant for silently takes its default:

CI configuration is invalid: parsing CI config: resolving includes: include local "/ci/comp.yml": unknown input arguments: enviroment

Several unknown names are listed together, comma-separated. GitLab lists them in the order the entry writes them; glci sorts them alphabetically. An inputs: for a file with no spec: header fails too, with Given inputs not defined in the `spec` section of the included configuration file, and an inputs: that is not a mapping fails with Given inputs must be a hash. A header is a spec: document followed by --- and the body. A single-document file with a top-level spec: key has no header, so it is refused when given inputs, as on GitLab. Included without inputs, it is refused all the same, as its spec: is a top-level key that is no job. Add the ---. An empty inputs: {}, or an inputs: with no value, supplies nothing and is accepted by any file.

These checks apply on every parse route. Under GLCI_PREFER_API=1 (or the Lint API fallback), a local: include that carries inputs: is inlined into the request like any other local include, interpolated with those inputs, so what is checked is the file in your working tree, the includes nested in it as well. A file whose header uses spec: include: is resolved by the offline parser instead.

An entry under rules: is checked only when its rules keep it, on both routes, since GitLab never reads a file whose rules drop it. glci decides those rules itself, against the simulated context, apart from the few the Lint API route leaves for GitLab (see Include rules).

A project: entry that lists several files under file: gives its inputs: to each file, and each is checked and interpolated against its own header, as GitLab does; so is each match of a wildcard local:.

Interactive TUI#

The TUI (glci with no subcommand) shows an input form with descriptions and defaults pre-filled. Required inputs are highlighted and validated before submission.

On a boolean field, Enter sets the value to false when it is true, and to true otherwise, so a field holding yes or TRUE becomes true. A value other than true or false is shown with GitLab’s error below the field. A boolean or number field left empty supplies no value, so the input takes its default, or fails as a missing required input.

An input whose default/options come from rules: is shown blank and unmarked: the form does not evaluate the rules, so nothing is pre-filled and the matching rule’s options: are not enforced there. They are still enforced when the pipeline is resolved, so a value the rule forbids fails the run rather than the form.

Esc