Skip to main content

loom context

Generate GitLab pipeline context files from the current git branch.

GitLab-format runs evaluate workflow:rules and rules: against pipeline variables that only exist on a GitLab runner. loom context init derives a loom.gitlab-pipeline-context.v1 file from repository facts so loom check, loom compile, and loom run can select the same jobs GitLab would, without a hand-written JSON file.

Canonical command usage​

Use the core CLI command reference for the exact loom context and loom context init synopsis, flags, and displayed defaults.

loom context​

loom context is a command group. Invoking it without a subcommand prints help for the group and exits successfully. Today the group contains one subcommand: init.

loom context init​

Write .loom/contexts/<name>.json beneath the repository root.

Behavior​

  • --as push|mr is required and selects the pipeline shape to mimic.
  • --name <name> defaults to the --as value. Names use letters, digits, ., _, or - (max 64 characters, no leading .).
  • The command fails when the file already exists unless --force is set.
  • HEAD must be a branch; a detached HEAD is rejected.
  • The default branch is the short name of origin/HEAD, falling back to main when the remote head is unknown.

What it writes​

Field--as push--as mr
CI_PIPELINE_SOURCEpushmerge_request_event
CI_COMMIT_BRANCHcurrent branchnot set
CI_COMMIT_REF_NAMEcurrent branchcurrent branch
CI_COMMIT_REF_SLUGslug of the branchslug of the branch
CI_DEFAULT_BRANCHdefault branchdefault branch
CI_COMMIT_SHA / CI_COMMIT_SHORT_SHAHEADHEAD
CI_COMMIT_BEFORE_SHAfirst parent of HEAD, or the zero SHAthe zero SHA
CI_MERGE_REQUEST_SOURCE_BRANCH_NAMEnot setcurrent branch
CI_MERGE_REQUEST_TARGET_BRANCH_NAMEnot setdefault branch
changesbase parent, head HEAD; omitted for a root commitbase default branch, head HEAD

changes never lists paths, so rules:changes resolve through git as described for loom check. No runner_tags are written; add them by hand when a job requires tags.

Commit hashes are pinned at generation time. Re-run with --force after new commits when a rule depends on CI_COMMIT_SHA or changes.

Examples​

Generate a default-branch push context and run against it:

loom context init --as push --name main
loom run --local --context main

Generate a merge request context named mr:

loom context init --as mr
loom check --context mr

Short context names​

--context <name> without a path separator or .json suffix resolves to .loom/contexts/<name>.json. Any value containing / or ending in .json is read as a project-relative path exactly as before. A missing short name fails with the resolved path and the loom context init command that creates it.