Context Simulation

glci simulates different CI pipeline contexts so you can test how rules: evaluate without pushing to GitLab. Without --context, it simulates the pipeline that pushing HEAD would create - see Default context.

Usage#

glci run --context branch=main
glci run --context merge_request --mr-source feature --mr-target main
glci run --context tag=v1.2.3
glci run --context env=production
glci run --context tag=v1.0 --env RELEASE=true
glci show --context merge_request

Default context#

When no context is given, glci picks it from the checked-out HEAD:

When several branches share the commit, the first by name is used.

The merge_request fallback has no ref to name, so CI_COMMIT_REF_NAME and CI_MERGE_REQUEST_SOURCE_BRANCH_NAME are empty.

An explicit choice always wins, in this order: --context, the context of the -p/--pipeline preset, then --mr-source/--mr-target or the preset’s mr_source/mr_target, which without a context imply merge_request. show, jobs, variables and run refuse a context that does not parse (invalid --context: ..., or invalid context in pipeline preset "<name>": ...) rather than fall through to the default, and lint, merged and doctor, which take the preset’s context for the predefined variables their include: entries expand against, refuse such a preset too.

When glci picked the context itself, glci show, glci jobs, glci variables, glci run and glci retry say which one on stderr, and the TUI says it under its titles:

$ glci jobs
glci: no --context given, assuming branch=main (checked-out branch)

The reason in parentheses is one of checked-out branch, tag at detached HEAD, branch tip at detached HEAD, remote branch tip at detached HEAD, no branch or tag at HEAD or not a git repository. On a terminal, glci show puts the line at the top of its paged output instead of stderr. glci run prints it once the pipeline is prepared; when the workflow rejects the pipeline, the error names the assumed context instead. --json drops the line, and glci run --json carries it on the pipeline_start event as assumed_context and assumed_context_reason. The bare glci TUI has no --context flag: its launch-screen count and Browse Pipeline are always planned under the default context, and the line appears under the launch screen’s and Browse Pipeline’s titles. The run form’s context field, left empty, uses the same default, and the TUI shows the line under the running pipeline’s title. glci retry replays the context the original pipeline ran under, so it prints the line only for a pipeline recorded before glci kept that context, whose retried jobs run under the default for what is checked out now.

The default models a push with no merge request open for the branch; on GitLab, pushing a branch with an open merge request also creates a merge request pipeline. On a feature branch the default is a push pipeline, so a workflow that accepts only merge requests and the default branch rejects it - as GitLab does for that push. See workflow rules. Pass --context merge_request to simulate the merge request pipeline instead, or make it the project’s norm with a pipeline preset:

[pipelines.mr]
context = "merge_request"
glci run -p mr

On the default branch the default includes jobs gated on $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH, typically deploy jobs, so check glci show before glci run there.

The changes diff#

rules: changes: follows the context, and compares what GitLab’s pipeline for it would:

With --dirty, the default, the diff runs to your working tree instead of HEAD, because that is what the dirty overlay commits for the run: uncommitted edits, deletions and untracked files that git does not ignore count as changed, in a push’s diff, a merge request’s and a compare_to: diff alike. The overlay is a commit the remote does not have, so on a branch the remote already has at HEAD the diff is your uncommitted changes. A new branch and a tag still have no diff, however much is uncommitted. --no-dirty, a preset’s dirty = false, and --git-strategy remote or none lay no overlay, so they diff to HEAD. So do the job and workflow rules of a run whose overlay fails, which runs HEAD; its include rules were decided while the overlay was being built, against the working tree (see Dirty mode). The preview commands (glci jobs, show, variables, lint, merged, doctor) have no --dirty flag and diff to the working tree unless [defaults] dirty = false or the -p preset turns it off, as glci run would.

A diff that changes no file, such as one from git commit --allow-empty, makes every changes: match in glci, while GitLab matches none.

CI_COMMIT_BEFORE_SHA is the commit a branch push compares from, the remote’s commit for the branch. It is the all-zero SHA when the remote does not have the branch or already has HEAD, and in a tag or merge request pipeline, as on GitLab. It describes the push of HEAD alone, so on a branch the remote has at HEAD it stays all-zero while changes: compares your uncommitted changes.

Context types#

Each context type sets specific CI variables that drive rules: evaluation:

branch#

glci run --context branch=main

Sets CI_COMMIT_BRANCH, CI_COMMIT_REF_NAME, CI_COMMIT_REF_SLUG, CI_DEFAULT_BRANCH, and CI_PIPELINE_SOURCE=push.

merge_request#

glci run --context merge_request --mr-source feature/login --mr-target main

Source defaults to the current git branch, target defaults to the detected default branch. Sets CI_PIPELINE_SOURCE=merge_request_event and the 23 CI_MERGE_REQUEST_* variables a detached merge request pipeline publishes — see Merge request variables.

tag#

glci run --context tag=v1.0.0

Sets CI_COMMIT_TAG, CI_COMMIT_REF_NAME, CI_COMMIT_REF_SLUG, and CI_PIPELINE_SOURCE=push. Does not set CI_COMMIT_BRANCH.

env#

glci run --context env=production

Sets CI_ENVIRONMENT_NAME and CI_PIPELINE_SOURCE=push, while preserving the current branch/tag from git.

CI variables by context type#

Variables not listed here (CI_COMMIT_SHA, CI_PROJECT_NAME, etc.) are derived from git and remain the same across all contexts.

Variablebranch=Xmerge_requesttag=Xenv=X
CI_COMMIT_BRANCHX(not set)(not set)(from git)
CI_COMMIT_TAG(not set)(not set)X(from git)
CI_COMMIT_REF_NAMEXsource branchX(from git)
CI_COMMIT_REF_SLUGslug of Xslug of source branchslug of X(from git)
CI_DEFAULT_BRANCHresolved(resolved)(resolved)(resolved)
CI_PIPELINE_SOURCEpushmerge_request_eventpushpush
CI_MERGE_REQUEST_*(not set)23 variables(not set)(not set)
CI_OPEN_MERGE_REQUESTS(not set)<project path>!1(not set)(not set)
CI_ENVIRONMENT_NAME(not set)(not set)(not set)X
CI_COMMIT_BEFORE_SHAthe remote’s commit for X, or all-zero (The changes diff)all-zeroall-zeroas branch= for the checked-out branch

Merge request variables#

--context merge_request publishes the 23 CI_MERGE_REQUEST_* variables a detached merge request pipeline publishes on GitLab, plus CI_OPEN_MERGE_REQUESTS, which GitLab publishes on the same pipeline because the merge request being built is itself an open one for its source branch. There is no merge request locally, so the values describing one are synthetic; the rest are derived from git or mirror the project’s own CI_PROJECT_* values. Three are conditional on what the local repository can supply and are marked below.

Variableglci value
CI_MERGE_REQUEST_EVENT_TYPEdetached
CI_MERGE_REQUEST_SOURCE_BRANCH_NAMECurrent git branch (or --mr-source)
CI_OPEN_MERGE_REQUESTS<CI_PROJECT_PATH>!1, omitted when the project path is not derivable
CI_MERGE_REQUEST_TARGET_BRANCH_NAMEDefault branch (or --mr-target)
CI_MERGE_REQUEST_DIFF_BASE_SHAgit merge-base HEAD <target>, resolving <target> as a local branch or as origin/<target>, omitted when uncomputable. Inside a job, the served repository’s commit with that merge base’s files, when the target branch is served (see below)
CI_MERGE_REQUEST_REF_PATHrefs/merge-requests/1/head
CI_MERGE_REQUEST_IID1
CI_MERGE_REQUEST_ID, CI_MERGE_REQUEST_DIFF_ID1
CI_MERGE_REQUEST_TITLElocal
CI_MERGE_REQUEST_DESCRIPTIONempty
CI_MERGE_REQUEST_DESCRIPTION_IS_TRUNCATEDfalse
CI_MERGE_REQUEST_DRAFTfalse
CI_MERGE_REQUEST_SQUASH_ON_MERGEfalse
CI_MERGE_REQUEST_SOURCE_BRANCH_PROTECTED, CI_MERGE_REQUEST_TARGET_BRANCH_PROTECTEDfalse
CI_MERGE_REQUEST_SOURCE_BRANCH_SHA, CI_MERGE_REQUEST_TARGET_BRANCH_SHAempty
CI_MERGE_REQUEST_PROJECT_ID, CI_MERGE_REQUEST_SOURCE_PROJECT_IDCI_PROJECT_ID (0)
CI_MERGE_REQUEST_PROJECT_PATH, CI_MERGE_REQUEST_SOURCE_PROJECT_PATHCI_PROJECT_PATH
CI_MERGE_REQUEST_PROJECT_URL, CI_MERGE_REQUEST_SOURCE_PROJECT_URLCI_PROJECT_URL — omitted without a remote

A simulated merge request is same-project, so the project and source project triples carry identical values — as they do on GitLab for a merge request that is not from a fork.

Empty is not the same as unset. CI_MERGE_REQUEST_DESCRIPTION, CI_MERGE_REQUEST_SOURCE_BRANCH_SHA and CI_MERGE_REQUEST_TARGET_BRANCH_SHA are published empty rather than omitted. They are defined, so if: $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA == null is false. GitLab fills the two SHAs only in merged-result pipelines, which have no local equivalent, so a detached pipeline publishes them empty; the description is empty for the same reason CI_MERGE_REQUEST_TITLE is local — there is no merge request to read one from.

Four variables are never published. CI_MERGE_REQUEST_LABELS, CI_MERGE_REQUEST_MILESTONE, CI_MERGE_REQUEST_ASSIGNEES and CI_MERGE_REQUEST_APPROVED are omitted entirely, because GitLab defines them only once the merge request carries a label, a milestone, an assignee or an approval. Publishing them as constants would make a rule see a defined variable where GitLab defines none.

CI_MERGE_REQUEST_DIFF_BASE_SHA is omitted when the merge base cannot be computed: the repository knows the target branch under no name, or it is a shallow clone that shares no history with it. GitLab always publishes it with a value, so an empty one is a shape it cannot produce.

The target branch is named bare (main), and a clone need not have a local branch of that name: git clone --single-branch -b feature, a worktree cut from a bare mirror and a CI checkout all leave origin/main with no local main. glci tries main, then origin/main, then refs/remotes/origin/main, and rules: changes: resolves the target the same way, so the two always describe the same range.

On a detached HEAD (a repository checked out at a SHA, a bisect, a rebase) git symbolic-ref names nothing, and a merge request with no source branch is a shape GitLab cannot produce. glci then names the commit by the tag an exact match finds, or by a branch whose tip it is. Only a commit reached by none of the three leaves CI_MERGE_REQUEST_SOURCE_BRANCH_NAME empty.

CI_MERGE_REQUEST_PROJECT_URL and CI_MERGE_REQUEST_SOURCE_PROJECT_URL are omitted in a repository with no remote, because CI_PROJECT_URL itself is — mirroring an absent value as an empty one would invent a project. A missing remote does not affect the _PATH mirrors, since CI_PROJECT_PATH falls back to local/<basename>. In a directory git cannot read as a repository, or one with no commits yet, neither pair is published, because nothing is derivable there.

--mr-source sets CI_MERGE_REQUEST_SOURCE_BRANCH_NAME and CI_COMMIT_REF_NAME only. The diff base is always the merge base of the target branch and the checked-out HEAD, as rules: changes: already is, so naming a source branch that is not the one checked out renames the variable without moving the diff.

CI_MERGE_REQUEST_REF_PATH names a ref the repository glci serves does not have: there is no refs/merge-requests/*, so git fetch origin "$CI_MERGE_REQUEST_REF_PATH" fails inside a job. Read the value; do not fetch it.

CI_MERGE_REQUEST_DIFF_BASE_SHA names a commit of your repository, which the served one does not have either. So a job is given the served repository’s commit for it instead, one with your merge base’s files: when glci serves the target branch (see The merge request’s target branch), the merge base of that branch and the commit the job checks out; when it serves the target branch as the commit under test, or not at all, the commit the served repository starts from, your HEAD’s files, provided your merge base has those files. git diff "$CI_MERGE_REQUEST_DIFF_BASE_SHA"...HEAD and git diff "$CI_MERGE_REQUEST_DIFF_BASE_SHA" HEAD then work in the job, at any GIT_DEPTH but the smallest (see below). Rules, include: rules: and rules: changes: use your repository’s commit, while a job, and a child pipeline’s rules, which inherit the job’s variables, get the served one, so glci variables and glci run --show-variables show different values for it. They are two SHAs for the same files: compare files, not SHAs, since the job’s value matches no commit in your repository or on GitLab. In any other case, the job gets your repository’s commit, and git commands against it fail.

CI_DEFAULT_BRANCH#

CI_DEFAULT_BRANCH is the project’s default branch, not the branch you happen to have checked out. glci resolves it from [defaults] default_branch, then refs/remotes/origin/HEAD, then main — so rules: if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH matches locally only where it would match on GitLab.

Because it is a project property, it is published in every context, together with CI_DEFAULT_BRANCH_SLUG, including in a repository with no commits yet, where nothing else is derivable from git. A rule comparing against it is never comparing against the empty string.

For a repository whose clone has no origin/HEAD and whose default branch is not main, name it in the project’s .glciconfig.toml:

[defaults]
default_branch = "master"

git remote set-head origin -a also works, by teaching git the project’s default branch so glci follows it — but it is per-clone, so it has to be repeated wherever the pipeline runs.

--env CI_DEFAULT_BRANCH=<branch> is a different thing: it overrides the variable for a single run, and does not change the branch the served repository advertises (below) or CI_DEFAULT_BRANCH_SLUG. GitLab behaves the same way — both keys are built from the project’s default branch rather than from each other — so use the config key when you mean “this is the project’s default branch”.

The repository glci serves to the runner advertises the same branch as its HEAD, the way a GitLab-hosted repository does, so git ls-remote --symref origin HEAD or a clone made inside the job agrees with $CI_DEFAULT_BRANCH. git remote set-head origin --auto does too, once the job has fetched that branch. The runner’s refspec fetch (see What the runner fetches) records no refs/remotes/origin/HEAD, exactly as in real CI.

Careful with diffs against the default branch. The repository glci serves is a single synthetic commit, and it carries the default branch as a second name for that same commit. A shallow checkout on another branch has no origin/<default-branch>, as on GitLab. Outside a merge request pipeline, a job that fetches it (git fetch origin main), or runs on the default branch, or sets GIT_DEPTH: 0, gets the commit under test under that name rather than the project’s real default branch: git diff origin/main HEAD comes back empty instead of a real diff. A job that lints or scans “only what changed against the default branch” therefore checks nothing locally, and passes. Don’t read a green result from such a job as meaningful — run it against real history. A merge request pipeline into the default branch is different: there the default branch is served with your checkout’s tree for it whenever your checkout has the branch and its files differ from the commit under test, so a two-dot diff against it lists the merge request’s changes, and a three-dot diff its own changes since the merge base (see The merge request’s target branch).

The pipeline’s ref in the served repository#

The repository glci serves is a copy of your checkout, but a job gets the ref its context names, whatever you have checked out. glci therefore also gives the served repository that ref, pointing at the commit the job checks out (the dirty-mode commit included):

ContextRef added
branch=<name>refs/heads/<name>
tag=<name>refs/tags/<name>
merge_requestrefs/heads/<source branch> (--mr-source, or the checked-out branch), and the target branch at a commit of its own (see The merge request’s target branch)
env=<name>the checked-out branch, which the copy already has, or on a detached HEAD the tag pointing at it
default contextthe branch or tag the default context picked: usually the checked-out branch, which the copy already has

So, on main, glci run --context branch=release gives a job that runs git fetch origin "$CI_COMMIT_BRANCH", reads origin/$CI_COMMIT_BRANCH, or clones with FF_USE_GIT_NATIVE_CLONE (git clone --branch release) the ref it expects, where before it failed with Remote branch release not found in upstream origin. Under --context tag=v1.2.3, git clone --branch v1.2.3 and git fetch origin tag v1.2.3 find the tag.

The ref is added to the copy served for that one pipeline, never to a cache, so the next run, in another context, does not see it. Like the default-branch alias above, it is another name for the commit under test, not your real branch or tag: git log origin/release shows the pipeline’s commit, not the history of the real release branch. An added tag is a lightweight tag, so git describe --exact-match without --tags does not match it, where GitLab’s annotated tag would.

A cross-project trigger gets the same treatment: a target mapped to a local checkout is served with the branch the trigger runs it on (trigger: branch: or the [projects] entry’s branch), whatever the checkout is on.

Some refs are left out:

For the first two the runner is asked for the pipeline’s commit alone (see below), so the checkout works and only a job that clones or fetches the ref itself fails, as does a native clone.

The mock server log (docker logs glci-mock, or glci-mock-<suffix> for a named daemon) says when a ref could not be added.

What the runner fetches#

The job payload glci hands gitlab-runner describes the pipeline’s ref the way GitLab’s does (Ci::BuildRunnerPresenter). The runner builds its fetch and its clone from the payload, plus GIT_FETCH_EXTRA_FLAGS and GIT_CLONE_EXTRA_FLAGS:

Contextrefref_typeRefspecs (GIT_DEPTH above 0)
branch=<name>, default context on a branch<name>branch+<sha>:refs/pipelines/<id>, +refs/heads/<name>:refs/remotes/origin/<name>
tag=<name>, default context on a tag<name>tag+<sha>:refs/pipelines/<id>, +refs/tags/<name>:refs/tags/<name>
merge_request<source branch>branch+<sha>:refs/pipelines/<id>, +refs/heads/<source branch>:refs/remotes/origin/<source branch>
env=<name>as the default context

<sha> is the commit the job checks out and <id> is CI_PIPELINE_ID, so the commit is always fetched, under the pipeline’s persistent ref refs/pipelines/<id>. With GIT_DEPTH: 0 (or below), the last refspec is replaced by every branch and every tag: +refs/heads/*:refs/remotes/origin/* and +refs/tags/*:refs/tags/*. When glci cannot vouch for the ref (one the served repository was not given, above; a branch while your checkout is on a detached HEAD, whose served copy may come from the cache with another run’s branches; or one your remote lacks under --git-strategy remote), the last refspec is left out, since a refspec naming a missing ref fails the whole fetch. The payload’s ref still names it.

The depth is sent as the payload’s depth, which is what the runner fetches and clones to, and what GIT_SUBMODULE_DEPTH defaults to. gitlab-runner never reads GIT_DEPTH itself. glci reads it as GitLab does: the job’s resolved GIT_DEPTH, whichever layer sets it, read as an integer prefix (5abc is 5; empty, abc or an unexpanded $VAR is 0, a full clone), or 20 when the pipeline does not set it, GitLab’s default for a project’s “Git shallow clone” setting. Like GitLab, glci does not add a GIT_DEPTH variable of its own to the job.

A shallow fetch takes the pipeline’s own ref and nothing else, as on GitLab. A job that needs another branch, such as origin/main on a feature branch, has to fetch it itself, or set GIT_DEPTH: 0. This also applies to --git-strategy remote, which fetches from your real remote: it gets the pipeline’s commit, 20 commits deep by default, and the pipeline’s ref when git ls-remote finds it on that remote under that name while the pipeline is prepared. That check never prompts for credentials and gives up after 15 seconds, and a failed check counts as the ref missing. An unpushed branch, or a --context ref that exists only locally, is left out, and the commit must then be on the remote. With FF_USE_GIT_NATIVE_CLONE and git 2.49 or newer in the helper image, the runner runs git clone --branch <ref> instead, for a branch or a tag alike, which fetches no refs/pipelines/<id>; with older git it falls back to the refspec fetch.

On GitLab, a merge request pipeline’s ref is refs/merge-requests/<iid>/head, and a shallow fetch takes only the persistent refspec. The served repository has no refs/merge-requests/* ref (see Merge request variables), and the runner’s native clone (git clone --revision refs/merge-requests/<iid>/head) would fail without it. glci therefore sends the source branch, the shape GitLab sends for a “legacy” detached merge request pipeline, one whose ref is the source branch rather than the merge request ref. The checkout is the same commit. The difference is that the job also has origin/<source branch>, which a GitLab merge request job fetched shallowly does not have, so a script reading origin/$CI_COMMIT_REF_NAME passes locally and fails on GitLab.

The merge request’s target branch#

A merge request job often fetches the branch it merges into and diffs against it:

git fetch origin "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
git diff --name-only "origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" HEAD

Under --context merge_request --mr-target release-1.0, glci looks the target branch up in your checkout, as refs/heads/release-1.0 or, failing that, refs/remotes/origin/release-1.0, and gives the served repository refs/heads/release-1.0 with that branch’s files. So git fetch origin release-1.0 finds it, and a two-dot diff, git diff origin/release-1.0 HEAD, shows the job’s changes against the target branch, the --dirty changes included. A local release-1.0 wins over origin/release-1.0 even when it is behind, as it does for CI_MERGE_REQUEST_DIFF_BASE_SHA, while GitLab diffs against the remote branch; keep the local branch up to date, or delete it, to match.

The default branch, the target when --mr-target is not given, is served the same way. The served repository already has it, as a second name for the commit under test (see CI_DEFAULT_BRANCH above), so in a merge request pipeline glci points that name at a commit with your checkout’s main (or, without a local main, origin/main) instead, whenever its files differ from the commit under test. After git fetch origin main, git diff --name-only origin/main HEAD then lists the merge request’s changes, the --dirty ones included. The repository’s HEAD still names main, so git ls-remote --symref origin HEAD agrees with $CI_DEFAULT_BRANCH, which does not change. The branch you have checked out gets the same treatment when it is the target of another source branch (--mr-source other --mr-target feature), which only makes a difference with --dirty changes. When the target has the files of the commit your --dirty changes are laid over, as main does with main checked out and --mr-source feature, that commit itself is served as the target.

The served repository has no history, so glci makes up as much as a job needs to compare the two branches, from your checkout’s merge base of HEAD and the target branch, the commit CI_MERGE_REQUEST_DIFF_BASE_SHA names:

When your branch has no commits of its own since the merge base (no changes at all, or only --dirty ones), the commit the served repository starts from, your HEAD’s files before any --dirty overlay, is the merge base, and the commit under test is served as it is, on top of it. When glci fell back to a full clone of your repository, which has your history, a merge base or target branch tip in it is served as itself, and so is the commit under test. Only the objects of the target branch’s and the merge base’s trees that the commit under test lacks are copied from your checkout, never their history; a merge base whose files your checkout cannot give, as a partial clone may not, is left out, and the commit under test served on the target branch’s commit instead. What follows from that:

In a jobWorks?
git fetch origin "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"Yes
git diff origin/<target> HEAD, git diff --name-only origin/<target>, reading files with git show origin/<target>:<path>Yes, the trees are the real ones
git diff origin/<target>...HEAD, git merge-base origin/<target> HEADYes, at the default GIT_DEPTH of 20: the merge base has your merge base’s files, so the three-dot diff lists only the merge request’s own changes, as on GitLab. The merge base is HEAD’s parent, or its grandparent with --dirty changes, so any depth deeper than that finds it, even where GitLab’s would not, for a merge request with more commits than GIT_DEPTH. With GIT_DEPTH: 1 (or 2 with --dirty changes) there is no merge base, as on GitLab at too small a depth: the checkout is cut off above it
git diff "$CI_MERGE_REQUEST_DIFF_BASE_SHA"...HEAD, git diff "$CI_MERGE_REQUEST_DIFF_BASE_SHA" HEADYes, at the same depths: the job is given the served merge base’s SHA (see Merge request variables)
git log origin/<target>..HEADNot as on GitLab: it lists the commit under test, and the commit the --dirty changes are laid over, not the merge request’s commits
git rev-parse origin/<target>, HEAD or $CI_MERGE_REQUEST_DIFF_BASE_SHA compared with a real SHANo: the commits are glci’s, not your branches'

Without a merge base in your checkout (a shallow clone that shares no history with the target), CI_MERGE_REQUEST_DIFF_BASE_SHA is not published, and the commit under test is served on the target branch’s commit, so a three-dot diff still works, but compares with the target branch’s files rather than the merge base’s.

glci does not add the target branch when:

The runner’s own shallow fetch does not bring origin/<target>, as on GitLab (see What the runner fetches), so the job has to fetch it, as above. With GIT_DEPTH: 0 the runner fetches every branch, the target branch included. With FF_USE_GIT_NATIVE_CLONE under GIT_STRATEGY: clone and a shallow depth, the runner’s clone is single-branch, so the job’s git fetch origin <target> updates FETCH_HEAD only, as on GitLab: diff against FETCH_HEAD, or fetch "$T:refs/remotes/origin/$T".

Like the pipeline’s ref, the target branch is added only to the copy served for that one pipeline, and a default branch and the commit under test are moved only there, never in the daemon’s bare repository cache or the mock server’s base cache, so the next pipeline, in another context, does not see any of it: a branch pipeline gets the default branch as the commit under test again, and the commit under test as it was, off the target branch’s history. Reusing the mock server’s cache costs a merge request pipeline only the few commits above and the files they change, sent with the request.

Comparing contexts#

# Compare job sets across contexts
diff <(glci show --json --context branch=main) \
     <(glci show --json --context tag=v2.0.0)

Combining context with –env#

--env adds or overrides variables on top of the context-derived set. Precedence: --env > context-derived > git-derived. See Variables & Secrets for the full table.

glci run --context branch=staging --env DEPLOY_ENV=staging
glci run --context tag=v1.0 --env-file release.env

--env/--env-file work the same way on glci show, glci jobs, and glci variables, so you can preview which jobs a variable-scoped rules: gate selects — without running anything:

# Which jobs run when DEPLOY_ENV=prod, under a tag pipeline?
glci show --context tag=v1.0 --env DEPLOY_ENV=prod
# ...and under a merge request pipeline?
glci jobs --context merge_request --env DEPLOY_ENV=prod

Include rules#

The context also decides include: rules. An entry is kept when its first matching rule has no when: or when: always, and dropped when that rule says when: never or no rule matches. A dropped file is never read, so a missing or broken file behind a rule that does not match is not an error, as on GitLab.

include:
  - local: ci/release.yml        # defines publish
    rules:
      - if: $CI_COMMIT_TAG

build:
  script: make
$ glci jobs --context branch=main
JOB    STAGE  WHEN        ALLOW_FAILURE  NEEDS
build  test   on_success
$ glci jobs --context tag=v1.0.0
JOB      STAGE  WHEN        ALLOW_FAILURE  NEEDS
build    test   on_success
publish  test   on_success

The rules are decided the same way on the Lint API route (GLCI_PREFER_API=1, or the fallback when the offline parse fails), so GitLab’s lint does not re-decide them against its default branch, with these exceptions:

Some rules glci cannot decide: a rule using regexp: in exists: or changes:, project:/ref: in exists:, or an exists: in a project: or component: file whose tree cannot be listed (a token without read_api, a 403/404, offline, a network error; see Listing a project’s files for rules: exists: fails). Offline the include is kept, with a warning (include local "ci/deploy.yml": glci cannot evaluate rules:exists:regexp; the include is kept), since dropping it could lose jobs GitLab runs. GitLab may leave such an include out unread, so one whose location is invalid (not .yml/.yaml) or whose file does not resolve is dropped, with a warning, rather than failing the parse, and a rule GitLab refuses inside that file does not refuse the config either. On the Lint API route the entry is left for GitLab. On a very large tree the listing stops at 20,000 files (or 200 pages of the repository tree API), and exists: there is then assumed to match, even for an exact path (GitLab checks exact paths against the whole tree), with the warning include rules in "<project>" at "<ref>": listing its files stopped at <N> files; a rules:exists: there is assumed to match. See Known limitations.

The warnings go to stderr, prefixed glci:, on the commands that parse in the CLI (glci lint, jobs, show, variables, merged). On glci run the daemon parses, so they go to the daemon log (glci daemon logs), prefixed daemon:; a downstream pipeline’s go to its trigger job’s log.

Context presets#

Save frequently-used contexts in .glciconfig.toml or ~/.glci/config.toml. A preset in the project file is added to the global ones, and replaces a global preset of the same name whole:

[contexts.staging]
context = "branch=staging"
env = { DEPLOY_ENV = "staging" }

[contexts.mr-to-main]
context = "merge_request"
mr_source = "feature/current"
mr_target = "main"

Use by name:

glci run --context staging
glci show --context mr-to-main

The TUI run form’s context field takes a preset name too.

Wherever a preset is named, by --context <name>, by a pipeline preset’s context = "<name>" or in the TUI run form, the run gets the entry’s context, mr_source/mr_target and env. glci show, glci jobs and glci variables resolve the name the same way, so they list the jobs and variables the run is prepared with:

Context presets can also be embedded in pipeline presets:

[pipelines.quick]
stages = ["lint", "test"]
context = "merge_request"
Esc