Context Simulation

glci simulates different CI pipeline contexts so you can test how rules: evaluate without pushing to GitLab. The default context is merge_request.

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

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_DEFAULT_BRANCH, and CI_PIPELINE_SOURCE=push.

merge_request (default)#

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, CI_MERGE_REQUEST_SOURCE_BRANCH_NAME, CI_MERGE_REQUEST_TARGET_BRANCH_NAME, CI_MERGE_REQUEST_IID=1, and CI_MERGE_REQUEST_TITLE=local.

tag#

glci run --context tag=v1.0.0

Sets CI_COMMIT_TAG, CI_COMMIT_REF_NAME, 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_DEFAULT_BRANCHdetected(from git)(from git)(from git)
CI_PIPELINE_SOURCEpushmerge_request_eventpushpush
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME(not set)source branch(not set)(not set)
CI_MERGE_REQUEST_TARGET_BRANCH_NAME(not set)target branch(not set)(not set)
CI_MERGE_REQUEST_IID(not set)1(not set)(not set)
CI_MERGE_REQUEST_TITLE(not set)local(not set)(not set)
CI_ENVIRONMENT_NAME(not set)(not set)(not set)X

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

Context presets#

Save frequently-used contexts in .glciconfig.toml or ~/.glci/config.toml:

[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

Context presets can also be embedded in pipeline presets:

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