Variables & Secrets

Jobs receive variables from multiple sources, layered by precedence (lowest to highest):

PrioritySourceHow to set
1 (lowest)CI-derivedAutomatic (git SHA, branch, etc.)
2Global YAMLvariables: at top of .gitlab-ci.yml, plus a matched workflow: rules: variables: which overrides it
3Job YAMLvariables: inside a job definition, its parallel: matrix: values, and a matched rules: variables:, which overrides both
4Dotenv artifactsartifacts: reports: dotenv: from dependency jobs (see Dotenv imports)
5Instance variablesFetched from GitLab API (admin token; --secrets all)
6Group variablesFetched from GitLab API (--secrets all)
7Project variablesFetched from GitLab API
8Trigger variablesIn a child or cross-project pipeline only: what the trigger job forwarded
9--env flagsglci run --env KEY=VALUE
10--env-fileglci run --env-file .env.local
11Pipeline preset envenv of the --pipeline preset, over the env of the [contexts] preset the context names
12 (highest).glci.envAuto-loaded from project root (add to .gitignore)

This is GitLab’s order. A job’s variables: block overrides the global block and nothing else: dotenv imports, the instance, group and project CI/CD variables, and the pipeline’s own variables all override it. Among the CI/CD variables the more specific scope (project) wins over the broader ones (group, instance). Within the group layer the same rule applies down the hierarchy: for org/team/project, a variable defined on org/team overrides the same key on org.

Rows 9-12 stand in for the variables you would give a pipeline on GitLab — the ones you enter when you run a pipeline by hand, or pass to the API or a trigger — which outrank everything else there. So --env overrides a job’s own value. In a child or cross-project pipeline rows 9-11 do not apply directly: what the parent was run with reaches it only through forward: pipeline_variables, as row 8.

deploy:
  variables:
    DEPLOY_ENV: staging
  script: echo $DEPLOY_ENV
$ glci run --env DEPLOY_ENV=prod      # prints prod, as a pipeline variable does on GitLab

A project CI/CD variable DEPLOY_ENV overrides it the same way. Runner settings are variables too: a job’s own GIT_STRATEGY: none or GIT_DEPTH: 1 overrides the global block and glci’s default, and yields to any of rows 4-12 that sets the same key.

Dotenv imports#

A job imports the dotenv report of each job it depends on, as GitLab does:

A trigger job imports dotenv the same way, from its needs: or from every earlier stage (GitLab does not allow dependencies: on a trigger job). The imported values are in its own scope, so its trigger: project: and trigger: branch:, and the variables: it forwards, can use them. It forwards them downstream only with forward: pipeline_variables: true; see Variable forwarding.

Workflow rule variables share the global layer because that is where GitLab puts them: the matched rule merges into the pipeline’s root variables, so every row below it still overrides them. A matrix value is part of its job’s variables:, as on GitLab, so --env PROVIDER=gcp overrides the PROVIDER of every shard; the shard names, which are decided when the matrix expands, do not change. variables set for a job in [jobs."<name>"] overrides are written into the job’s variables: and rank with it.

Difference from GitLab: glci adds a few variables of its own to every job above row 12: the embedded registry’s CI_REGISTRY_* credentials and the per-job set (CI_JOB_ID, CI_JOB_NAME, CI_JOB_TOKEN, CI_NODE_INDEX/CI_NODE_TOTAL on a shard, …). GitLab ranks those predefined variables below everything in the table, so a CI/CD variable or --env of the same name overrides them there. glci keeps its own so the job reaches the embedded registry and the mock server, and so a split runs with the shard numbers it was scheduled with.

The same order decides what a rules: condition sees — see Variables in scope for rules:.

In variables:, an unquoted yes, no, on, off, true or false, in any letter case, is a boolean, as GitLab’s YAML parser reads it, so the variable is set to true or false, as on GitLab: DEBUG: on gives DEBUG=true. Quote the word to keep it: DEBUG: "on".

The same goes for a variable’s name. GitLab reads an unquoted ON: or no: key as a boolean, which is no variable name, and refuses the pipeline (jobs:<name>:variables:true key must be an alphanumeric string); so does glci, for the top-level variables:, a job’s, a rule’s, a service’s and a parallel: matrix: entry, including one a job gets through extends: or !reference. Quote the name to use the word: "ON": x.

Numbers are read the same way. GitLab’s YAML parser reads YAML 1.1 integers, so an unquoted hexadecimal, binary or octal number, one with _ or , between its digits, or one with colons is set to its decimal value. Colons follow the parser’s own base-60 formula, not YAML 1.1’s (which makes 1:30 90):

WrittenValue
HEX: 0x1F31
BIN: 0b113
OCT: 0108 (a leading zero is octal, so MODE: 0755 is 493)
UND: 1_0001000
COM: 1,0001000
B60: 1:305400 (a:b is a×3600 + b×60, so TIME: 12:30 is 45000)
B60S: 1:2:33723 (a:b:c is a×3600 + b×60 + c)

Quote the value to keep the text: TIME: "12:30", MODE: "0755".

Inheriting global variables#

inherit: variables: decides which global variables (row 2 of the table) a job gets. true, the default, is all of them; false is none; a list is only the keys it names:

variables:
  DEPLOY_TOKEN_SCOPE: global
  REGION: eu

isolated:
  inherit:
    variables: false
  script: env          # no DEPLOY_TOKEN_SCOPE, no REGION

regional:
  inherit:
    variables: [REGION]
  script: env          # REGION=eu, no DEPLOY_TOKEN_SCOPE

glci applies the setting everywhere it uses a job’s variables, as GitLab does:

The variables a matched workflow: rules: rule adds are part of the global layer, so inherit: variables: filters them too: a job with inherit: variables: false gets none of them, and a list has to name one for the job to get it.

The setting only narrows the global layer. Every other row of the table still applies: predefined variables, the job’s own variables:, dotenv imports, CI/CD variables, what a trigger job forwarded, --env, --env-file, preset env and .glci.env.

Variables in scope for rules:#

A job’s rules: are evaluated against the job’s own scope, not just the pipeline-wide set. That means an if: can test the job’s own variables: block and the values injected by parallel: matrix:, the same as on GitLab:

deploystacks:
  script: ./deploy.sh
  parallel:
    matrix:
      - PROVIDER: aws
        SKIP: "false"
      - PROVIDER: ovh
        SKIP: "true"
  rules:
    - if: '$SKIP == "false"'    # only the aws shard is created

Matrix expansion happens before rules are evaluated, so each shard is judged against its own values — using a matrix variable in rules:if: is the documented way to include or exclude individual shards.

The job’s own values do not win outright. GitLab ranks a job’s variables: below everything a person supplied for the run, in its rules as in its environment. Anything from rows 5-12 of the table above — instance, group and project CI/CD variables, what a trigger job forwarded, --env, --env-file, a preset’s env, .glci.env — decides a rule even where the job declares the same name (dotenv imports do not exist yet when rules are evaluated, and in a child or cross-project pipeline only .glci.env of the local layers reaches its rules, see Variable forwarding):

$ glci jobs --env DEPLOY_ENV=staging     # a job's own DEPLOY_ENV does not override this

What the job’s variables: block does decide is every key nothing above it defines, which is the common case and the one this scope exists for.

Inheriting a global is not redeclaring it. glci folds into each job the globals it inherits, and those inherited entries keep global precedence rather than being promoted. Only a key the job sets to a value that differs from the global counts as the job’s own — redeclaring a key with the identical value is indistinguishable from inheriting it, so it is treated as inherited, and the same is true of a matrix: value that happens to equal a same-named global. The exception is a key the job does not inherit (inherit: variables:): nothing was folded in for it, so the job’s value is its own whatever it is.

The three local-resolution commands never fetch API variables, so glci jobs, glci show and glci variables cannot show you a rule that an instance, group or project variable would decide differently on a real run.

Inspecting resolved variables#

When a value isn’t what you expect — or a rules: clause matches when it shouldn’t (or doesn’t when it should) — inspect the resolved variables instead of guessing.

glci variables — static inspection#

glci variables resolves the variables for every job without running the pipeline, attributing each value to the layer it came from and showing how each job’s rules: evaluated. Because nothing executes, jobs that are excluded by their rules: are still shown (marked excluded), which is the main way to debug why a rule did or did not match.

It focuses on the variables you actually control. Predefined CI_* variables are hidden by default (pass --all to include them), with one exception: any predefined variable referenced by a rule’s if: is always shown, so you can see the value the rule was evaluated against.

glci variables                          # all jobs, current context
glci variables deploy_prod              # only the named job(s)
glci variables --stage test             # only jobs in a stage
glci variables --context branch=main    # simulate a different context
glci variables --all                    # include predefined CI_* variables
glci variables --json                   # machine-readable output

Example:

deploy_prod  (stage: deploy)  [included, when: on_success]

  Rules:
    #0  $CI_COMMIT_BRANCH (main) == $CI_DEFAULT_BRANCH (main)  → true

  Variables:
    KEY               VALUE       SOURCE
    CI_COMMIT_BRANCH  main        predefined
    GREETING          hello       global
    DEPLOY_ENV        production  rules

The Rules section shows each rule’s condition with every $VAR expanded to its value, and whether the condition evaluated true or false (a failing changes:/exists: rule appends a short reason). The Variables SOURCE column reports where the winning value came from, and the rows are grouped by it in precedence order: predefined, global, job, rules, flag (--env), env-file, preset, glci-env, or predefined:job (per-job CI_JOB_NAME/CI_JOB_STAGE).

A job excluded by its rules still prints, so you can see why:

only_dev  (stage: test)  [excluded, when: never]

  Rules:
    #0  $CI_COMMIT_BRANCH (main) == "dev"  → false

  Variables:
    KEY               VALUE    SOURCE
    CI_COMMIT_BRANCH  main     predefined
    ...

With --json, each job carries a rule_trace (with matched booleans and the refs map of referenced variable values) and the full variables array — suitable for programmatic use.

Long values (e.g. CI_COMMIT_DESCRIPTION) and multi-line values are truncated to 512 characters and shown on a single line so the table stays readable. Pass --expand to print full, raw values. (--json always carries the full value.)

glci variables resolves everything available locally (no Docker, no network). It does not fetch GitLab API group/project secrets or runtime values (dotenv, CI_JOB_ID); for those, use --show-variables below.

glci run --show-variables#

Adding --show-variables to glci run prints each job’s fully resolved variable set — including API secrets, dotenv imports, and runtime CI_* values — together with its rule trace, to the terminal just before the job’s log:

glci run --show-variables                 # secrets masked, predefined CI_* hidden
glci run --show-variables --unmask        # reveal masked/secret values
glci run --show-variables --all-variables # include predefined CI_* variables
glci run --show-variables --expand        # do not truncate long values
  deploy ── variables ──
    Rules:
      #0  $CI_COMMIT_BRANCH (main) == $CI_DEFAULT_BRANCH (main)  → true

    Variables:
      KEY                   VALUE       SOURCE
      CI_COMMIT_BRANCH      main        predefined
      DEPLOY_ENV            production  job
      CI_REGISTRY_PASSWORD  [masked]    registry

Besides the sources glci variables reports, the SOURCE column here can read dotenv, api:instance, api:group, api:project, trigger (what the trigger job forwarded, in a child or cross-project pipeline) and registry (the embedded registry’s credentials). A matched rule’s variables: are part of the job’s own by the time it runs, so they read job here rather than rules. Each value is attributed to the layer that won under the precedence table at the top of this page, and the rows are grouped by layer in that order.

Like glci variables, predefined CI_* variables are hidden by default (use --all-variables), except those a rule references. Secret values (API group/project variables and any variable marked masked) are shown as [masked] by default; pass --unmask to print them in clear text.

Rule evaluation never quotes a value#

Rules are evaluated against expanded values, so an error raised while evaluating one could name a value rather than the $VAR that stood for it. None does.

The one route that mattered is now closed at its source rather than redacted. A right-hand side of =~ or !~ is compiled only when it is written as a pattern, so a variable holding something that is not one is never handed to the regex parser and has nothing to fail about — it is searched as text. A masked value can no longer produce a regex error because it can no longer produce a regex.

What remains is configuration rather than a value: a malformed /pattern/ literal, a string literal that does not lex – one left open, or spanning a newline – or a ${VAR} reference, which GitLab has no form for. None of them can hold an expanded value, because the expression is parsed as it was written and variables are resolved into operands rather than back into the text. The pattern error is reported by its error code alone and never repeated, since it is already on screen in the expression beside the message:

    #0  $DEPLOY_TOKEN ([masked]) =~ /[invalid/  → false  (if: could not be evaluated: invalid regex: missing closing ])

The reason string carries no value, whether or not any variable in the expression is masked, and regardless of --mask. The annotation ([masked]) is masked on its own terms, exactly as it is in the table below it.

The same message reaches every consumer of the trace: the glci variables table, glci run --show-variables, the --json form of either, the glci: warning: line any config-resolving command writes to your terminal, and the copy of that warning in ~/.glci/daemon.log on glci run. The if: expression printed beside it is always the source text, where a variable appears as its name.

The regex error code is kept on purpose. It narrows the failure to one of a fixed set — missing closing ], trailing backslash, and so on — which says a little about the value’s shape and nothing about its contents. Dropping it would cost you the reason the rule failed and buy very little.

In the rule trace, a shadowed secret is masked by its value, not merely by its name. A masked value stays [masked] there even when a later layer supplies something else under the same name — one of the variables glci injects for its embedded registry shadowing a masked project variable, say. That layer does not exist yet when rules: are evaluated, so the value the trace tested really is the masked one. A variable whose own winning layer is secret is masked whatever value is shown for it.

A value you supplied yourself is still shown. --env, --env-file, preset env: and .glci.env all outrank the API layers and are part of what rules are evaluated against, so glci run --show-variables --env TOKEN=local-dev prints $TOKEN (local-dev) even when the project defines a masked TOKEN — that is what the rule was tested against, and hiding it would defeat the point of the trace.

Remote secrets#

Project, group, and instance CI/CD variables are fetched automatically when a GitLab token is available. Results are cached in daemon memory for 6 hours (never written to disk), keyed by GitLab instance, project path, and a fingerprint of the token (a hash, never the token itself). The same path on two instances never shares an entry, and variables fetched with one token are never served to a run holding another: a maintainer or admin token’s group and instance variables stay out of reach of a later run with a narrower token. A rotated token, such as a refreshed OAuth token, misses once and fetches again. A fetch that failed or got a 404 for the project is not cached, so the next run tries again. The cache is lost on daemon restart.

If GitLab answers 404 for the project, the run continues without project variables and the daemon log names the project path and where it came from (--project or the git remote) — see troubleshooting.

A multi-project downstream (trigger: project:) gets its target project’s group and project variables, fetched the same way: with the same token and --secrets scopes, through the same cache, keyed by the target’s path. It keeps the run’s instance variables. The parent project’s group and project variables never reach the target’s jobs.

glci run --secrets all      # project + group + instance variables (default)
glci run --secrets project  # project variables only
glci run --secrets none     # skip remote fetching entirely
glci run --refresh-secrets  # force a fresh fetch, bypassing the cache

A run started from the TUI fetches the same scopes as glci run with no --secrets flag (all), and glci retry fetches the scopes the retried pipeline was started with.

Instance-level variables (GET /admin/ci/variables) require an administrator token. For non-admin tokens GitLab returns 403, and glci skips them silently — project and group variables are unaffected. This matches how real runners receive instance variables injected server-side; locally, glci can only read them when your token is allowed to. If your includes or jobs depend on an instance variable you can’t fetch (for example a non-admin token on a shared instance), supply it locally instead via .glci.env, --env, or a pipeline preset.

Configure the cache TTL in .glciconfig.toml:

[gitlab]
secrets_ttl = "6h"   # default; set to "0" to disable caching

Local overrides with .glci.env#

Auto-loaded KEY=VALUE file from project root for local secrets. Add it to .gitignore. Masked and file-type variable attributes from the GitLab API are preserved and passed to the runner. Values from this file are redacted out of include-resolution output on the same terms as any other local layer — see Masking in include output.

Variables in include:#

GitLab expands $VAR / ${VAR} in include: project:, ref:, and file: before fetching the included file, so a pipeline can point at a template repo through variables:

include:
  - project: $_GITLAB_TEMPLATES_REPO
    ref: $_GITLAB_TEMPLATES_REF
    file: '/includes/main.yml'

glci resolves these the same way. The variables available during include expansion are, lowest to highest precedence: predefined CI_* variables, the global variables: block (each value as a job gets it, so ENV: on is true), on glci run the instance, group and project CI/CD variables it fetched from the API (see Remote secrets), then your locally-supplied variables (--env, --env-file, pipeline preset env, .glci.env). glci run fetches the CI/CD variables before it parses, so an include path built from a project variable resolves there as on GitLab. The preview commands (glci jobs, show, variables, lint, merged, doctor) fetch none, so there the local layers stand in for the CI/CD variables GitLab would supply. GitLab itself never expands an include location against the global variables: block; glci’s offline parser does, and its lint-API route does not (see below).

The predefined layer is what GitLab has while it reads the configuration: the server variables (CI_SERVER_*) and the project and pipeline variables of the simulated context (CI_PROJECT_*, CI_COMMIT_*, CI_PIPELINE_SOURCE, CI_MERGE_REQUEST_*, CI_DEFAULT_BRANCH, CI_CONFIG_PATH, …). It is the same on every command that parses the pipeline. glci run, show, jobs and variables take the values from the context --context picks, or the one they assume without it; glci lint, merged and doctor, which have no --context, take them from the -p preset’s context or from the pipeline pushing HEAD would create. Override a single value with --env, for example --env CI_COMMIT_REF_NAME=main. Job variables such as CI_JOB_ID, CI_PROJECT_DIR or GITLAB_USER_LOGIN do not exist yet at that point, on GitLab or in glci, and neither do CI_PIPELINE_ID, CI_PIPELINE_URL and CI_PIPELINE_TRIGGERED, which GitLab sets only once the pipeline is saved or a job exists. (GitLab’s documentation lists CI_PIPELINE_TRIGGERED among the variables include: can use, but its code sets it per job.)

That makes the address GitLab documents for a component project testing its own components work as it does on GitLab: the component is fetched from your project at the commit you have checked out.

include:
  - component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/my-component@$CI_COMMIT_SHA

The commit has to be pushed, since glci fetches the component from GitLab, and the repository needs a GitLab origin remote, or CI_PROJECT_PATH is local/<directory name>.

A plain-string entry such as include: $TEMPLATE_URL is expanded before glci decides whether it is local: or remote:, as GitLab’s normalizer does, so a variable holding a URL makes a remote include.

On the lint-API route (GLCI_PREFER_API=1, or the fallback when offline parsing fails) glci expands the include: entries of your files before it sends them, with the predefined, fetched CI/CD (on glci run) and local layers above, once, after the file’s own input interpolation (the root against its spec: header first, then each inlined local file against its own header, with its entry’s inputs: and its defaults; a file with no header is expanded with its blocks as written), so GitLab resolves them at the commit and ref glci simulates. Otherwise GitLab would expand $CI_COMMIT_SHA and $CI_COMMIT_REF_NAME to its default branch, as a lint request names no commit. A variable glci does not have, such as a project variable only GitLab knows, is left for GitLab to expand, and so is a plain-string entry still holding one. The global variables: block is not used on this route, as GitLab never expands an include location against it. Nor is a masked variable: GitLab does not know it is masked, so glci leaves it as $VAR rather than send its value. The other expanded values, including ones from --env, --env-file, .glci.env or a preset, are sent to your GitLab instance’s lint API. An include: inside a file GitLab fetches (a project:, remote:, template: or component: file) is expanded by GitLab with its own values.

An include: entry’s rules: if: reads a narrower set: the global variables: block is not in it, on either parse route. See Include rules.

A spec: include: entry reads a narrower set: the global variables: block is not in it, in the root pipeline or an included file. See Input definitions from other files.

$[[ inputs.x | expand_vars ]] reads a narrower set: the global variables: block is not in it, and a masked variable is refused rather than expanded. See Functions.

On many self-managed instances (Drupal contrib’s gitlab_templates, for example) these are instance-level variables. glci fetches instance variables only with an admin token (see Remote secrets), and only glci run fetches CI/CD variables at all — so on the preview commands they are not available at include-expansion time. Supply any variable an include path depends on locally:

# .glci.env (gitignored)
_GITLAB_TEMPLATES_REPO=project/gitlab_templates
_GITLAB_TEMPLATES_REF=1.0.x

Inspect the resolved include paths with glci jobs or glci variables; a literal $VAR reaching the API (an HTTP 404 fetching projects/$VAR/...) means the variable wasn’t supplied at any of the layers above. If a path in that message reads [MASKED], the value was treated as a secret — pass --unmask to see it.

Masking in include output#

Include paths are expanded before they are fetched, so any warning or error naming one quotes the value, not the $VAR that stood for it. A variable holding a token would otherwise reach your terminal in clear text.

glci masks the same values GitLab masks, and no others: a variable is hidden when it is marked, never because its value looks secret. That mirrors mask_variables_from in GitLab, which masks a variable if and only if it is flagged masked. Guessing from shape would be worse than useless: a local run that hid a value GitLab then prints in a job log would tell you the secret was protected when it never was.

Variables fetched from the API carry GitLab’s own masked flag and need nothing further. For the local layers (--env, --env-file, preset env:, .glci.env) there is no such flag, so name them yourself — --mask is the local equivalent of ticking Mask variable in the GitLab UI:

glci merged --mask PRIVATE_TOKEN     # hide this variable's value
glci merged --unmask                 # print everything in clear text

--mask takes a variable name, not a value, so it applies whichever layer supplied it. Set it permanently for a preset in .glciconfig.toml:

[pipelines.deploy]
env = { PRIVATE_TOKEN = "glpat-xxxxxxxxxxxx" }
masked = ["PRIVATE_TOKEN"]

A project .glciconfig.toml may only add to a global preset’s masked list, never remove from it, so a cloned repository cannot unhide a variable you marked.

What GitLab will accept#

glci applies GitLab’s own masking requirements and refuses to hide anything GitLab would not, so what you see locally matches what a real pipeline prints. A value must be a single line, at least 8 characters, with no spaces, and use only letters, digits and _ : @ - + . ~ = /. A variable marked raw: is held to GitLab’s looser rule instead — any 8 or more characters with no whitespace. Only variables fetched from the API carry raw:, so a locally-supplied value is always held to the stricter rule; a local secret containing !, #, % or , cannot be masked, because GitLab would not mask it either without raw:.

Mark a name that none of those layers supplies, or one whose value GitLab would reject, and glci says so on stderr rather than quietly leaving it visible:

glci: warning: DEPLOY_PHRASE left visible: GitLab would not accept this value for masking, so hiding it
locally would misreport what a real pipeline does. …

That is the signal to change the value, not to work around it — GitLab will not mask it either.

Scope#

Redaction covers the percent-encoded and %q-quoted forms of a value as well as the raw one, so a secret containing / or " is still hidden once it reaches an API URL or a quoted path.

When an error quotes what a server sent back (a failed CI Lint API response, or the message on a failed component releases listing), glci masks the whole text first and only then shortens it to fit the error. A secret that runs past the cut is hidden in full, and none of its first characters show. The text is also flattened onto one line with control characters removed, so a server cannot forge a line in ~/.glci/daemon.log or send escape sequences to your terminal. The GitLab token the request was made with is masked in that text too, in case a proxy or the instance echoes it back, even with --unmask, which only reveals variable values. A failed CI/CD variables API response is handled the same way for the token, the only secret that request carries.

Redaction applies to glci lint, doctor, show, jobs, variables and merged, and to glci run — including the warnings and errors the daemon writes to ~/.glci/daemon.log, and the trigger job traces of child and cross-project pipelines.

lint and doctor carry the same variable flags as the other config-resolving commands, so a secret an include path interpolates can be marked there too. On doctor a mask warning arrives as a hint on the CI config row rather than as a free-standing line, because that command owns its report format.

When something is redacted, glci says so once on stderr and names --unmask, so a masked path is never mistaken for a failed one.

--mask redacts include-resolution output and makes expand_vars refuse the variable as GitLab does for a masked one. It does not mask the glci variables table, glci run --show-variables, or a job’s trace — for a job trace, GitLab’s runner does the masking from the variable’s own masked flag.

Child and cross-project pipelines (trigger: with include: or project:) expand their includes, and decide their include rules, against the downstream pipeline’s own set. Lowest to highest precedence: the downstream’s predefined CI_* variables (a child’s are its parent’s, with CI_PIPELINE_SOURCE=parent_pipeline; a multi-project pipeline’s are the target’s own, as its jobs get them: its branch, CI_PROJECT_* and CI_CONFIG_PATH, no CI_MERGE_REQUEST_*, and CI_PIPELINE_SOURCE=pipeline), the instance/group/project variables fetched from the API (a multi-project pipeline’s group and project variables are the target’s own, not the parent’s), the variables the trigger job forwards downstream (the parent’s global variables: the trigger job inherits, merged with its own variables:, and with forward: pipeline_variables its dotenv imports and the parent’s pipeline variables), and finally your local layers (--env, --env-file, pipeline preset env, .glci.env). CI_PIPELINE_SOURCE and CI_PARENT_PIPELINE_ID are the exception: a forwarded value, --env, --env-file and a preset’s env do not override them there, as they do not for the downstream’s job rules; a project CI/CD variable or .glci.env still does.

The forwarded layer is what GitLab expands a downstream include: against, so a child whose include says ref: $TEMPLATES_REF picks up the value the trigger job set. See Variables in a child’s include paths.

Token forwarding#

By default, the host’s real GitLab token is forwarded into jobs as CI_JOB_TOKEN. Disable with --no-token, or restrict which jobs receive it in ~/.glci/config.toml:

# ~/.glci/config.toml

[token]
forward_host_token = true
stages = ["deploy"]              # only deploy stage gets real token
jobs = ["release"]               # specific job names
job_patterns = [".*-publish$"]   # regex patterns

Jobs not matching the filter receive a synthetic mock-server token instead.

A project .glciconfig.toml may set [token] too, but it can only narrow what your global config allows — it decides whether your real token reaches scripts the repository wrote. forward_host_token = false in a project file is always honored; a project true is ignored when your global config explicitly set false; project filters are honored only when your global config sets none. Ignored keys are named in the glci: warning: .glciconfig.toml: ignoring ... line. See Token forwarding in a project config.

GitLab API token#

Required for include: project:, include: component:, fetching remote CI/CD variables, and auto-cloning trigger: project: targets.

Token resolution order (first match wins; --token flag always overrides):

  1. GITLAB_TOKEN or GITLAB_PRIVATE_TOKEN environment variable
  2. [gitlab] token in .glciconfig.toml / ~/.glci/config.toml
  3. glab auth credential-helper – supports keyring, OAuth2 refresh, and PAT/CI tokens
  4. Direct read of ~/.config/glab-cli/config.yml – legacy fallback

The simplest setup is glab auth login – the token is picked up automatically. The project path is auto-detected from your git remote; override with --project.

Exception: when the instance URL comes from a project .glciconfig.toml ([gitlab] url), every source except --token and [gitlab] token in that same project file is skipped – a file that travels with the repository must not be able to redirect your token to a host it picked, and that includes the token in ~/.glci/config.toml, which is your credential for your own instance. Otherwise requests go out unauthenticated and glci warns on stderr, naming the withheld source. See [gitlab] url in a project config.

glci’s own GitLab API requests that carry the token – include: project: and include: component: fetches, the CI Lint call and variables fetches – keep it on the instance they were sent to. The instance is the hostname: the same hostname on another port counts as the same instance; another hostname, subdomains included, or a hop from https to http does not. When a request is redirected off the instance, glci drops the PRIVATE-TOKEN, JOB-TOKEN and Authorization headers from that hop and every later one, including a hop back to the instance, and warns naming both addresses:

glci: warning: "https://gitlab.example.com" redirected a GitLab API request to "https://other.example.com", so the token was not sent with it. If that request fails, point the GitLab URL at the address that serves the API.

An include fetch warns once per parse, alongside the parse’s other warnings: on stderr for commands that parse locally (glci lint, glci jobs, glci variables), in ~/.glci/daemon.log for the pipeline glci run starts (the daemon parses it, with a daemon: prefix in place of glci:), and in the trigger job’s log for a downstream pipeline. A variables fetch warns on stderr, which for a pipeline run is ~/.glci/daemon.log. A read still follows the redirect, unauthenticated.

The CI Lint call is a POST and is never followed, on the instance or off it: a 301, 302 or 303 would turn it into a GET, which GitLab answers by linting the project’s default-branch config instead of the one glci sent, and a 307 or 308 would replay your CI config to the other address. glci stops with refusing to follow a POST redirect from "<from>" to "<to>" instead.

Either way, the configured GitLab URL is not the address that serves the API – point GITLAB_URL or [gitlab] url at the address that serves /api/v4, usually the one the redirect named. This covers glci’s own requests only, not the token that token forwarding passes into jobs as CI_JOB_TOKEN.

Fallback project path#

When no git remote is configured (common for local-only test repos), CI_PROJECT_PATH defaults to local/<dirname> so variables like $CI_PROJECT_PATH are always available in job scripts.

Parallel job variables#

Jobs expanded by parallel: receive the same node variables GitLab sets, so a split test suite really is split locally instead of every shard running the whole thing.

VariableValue
CI_NODE_INDEXThe 1-based index of the shard. Only set on jobs expanded by parallel:
CI_NODE_TOTALThe number of shards. 1 for a job without parallel:

Both forms are covered: parallel: 4 numbers its shards 1 to 4, and parallel: matrix: numbers each permutation over the total permutation count.

test:
  parallel: 4
  script:
    - pytest --splits $CI_NODE_TOTAL --group $CI_NODE_INDEX

On a shard both values are derived from the expansion and override anything the pipeline sets itself, so a stray CI_NODE_TOTAL in variables: cannot desynchronise a split. Without parallel: the 1 is only a default, and a CI_NODE_TOTAL the pipeline sets stands.

The variables a matrix: entry declares are in scope for the job’s rules:, so individual shards can be included or excluded by condition.

Difference from GitLab: CI_NODE_INDEX and CI_NODE_TOTAL are not. A rule testing either sees an empty value and glci will drop the job, where GitLab evaluates it against the shard’s real numbers. They are assigned from the expansion when the shard runs, which puts them below a job’s own variables: — a layer glci’s rule evaluation does not have yet. Tracked separately, along with the rest of the per-job predefined set (CI_JOB_NAME, CI_JOB_STAGE), which rules cannot see either.

For parallel: matrix: the permutations are enumerated the way GitLab enumerates them: in the order the matrix variables were declared, with the first-declared variable outermost. That order fixes both a shard’s name and its CI_NODE_INDEX, so a given index maps to the same combination locally as it does on GitLab.

deploystacks:
  parallel:
    matrix:
      - STACK: [app, monitoring]
        PROVIDER: [aws, gcp]

STACK is declared first, so the shards are deploystacks: [app, aws] (index 1), [app, gcp] (2), [monitoring, aws] (3), [monitoring, gcp] (4) — not the alphabetical PROVIDER-first pairing. Declaring PROVIDER first instead is a different pipeline: same four combinations, different names and indexes.

Because the shard name is an identifier, this is what glci run "deploystacks: [app, aws]", --skip/--manual filters, [jobs."<name>"] overrides, preset job lists and artifact lookups all match on. Copy a shard name out of the GitLab UI and it works unchanged.

Declaring the matrix through extends:, an include:, a YAML anchor, a merge key (<<:), or a !reference keeps the order it was written with — whether the reference points at another job’s parallel: matrix: or at a bare list under a hidden key, such as matrix: !reference [.matrices, deploy], in this file or an included one. A <<: merging a list of aliases contributes their variables in reverse list order, which is where GitLab’s YAML parser puts them too. Two shapes have no declared order to read, and fall back to alphabetical variable order:

Both are deterministic; only their shard names differ from the same matrix written inline.

glci lint reports the same diagnostics GitLab’s lint API returns for a parallel: block, so a matrix that would fail on push fails locally: parallel: outside 1-200, a matrix generating more than 200 jobs, an entry with no variables, and a value that is not a string or an integer (an unquoted 1.21, true, yes or off — quote them). A matrix over the job limit is left unexpanded rather than built, since a six-variable, ten-value matrix is a million jobs.

A variable declared with an empty list (VARIANT: []) crosses with nothing, so its entry generates no shards; a matrix that generates none at all — matrix: [], or every entry holding such a variable — removes the job from the pipeline, and any needs: on it, exactly as GitLab does.

Unsupported variables#

About 20 CI/CD variables cannot be set locally because they require a real GitLab server: CI_DEPLOY_*, CI_UPSTREAM_*, CI_EXTERNAL_PULL_REQUEST_*, KUBECONFIG, CHAT_*. GITLAB_USER_* variables are approximated from git config.

GLCI_PREFER_API#

Set GLCI_PREFER_API=1 to use the GitLab Lint API as the primary parser instead of the offline parser. Useful for edge cases where the offline parser differs from GitLab’s server-side behavior. A refusal both routes would make — a !reference GitLab cannot read, say — is reported as it stands rather than retried on the other parser; see how the routes back each other up.

Context-derived variables#

glci sets CI variables based on the --context flag. See Context Simulation for the full variable table per context type.

Esc