Skip to content

Builtin variables

Varlock provides a set of builtin VARLOCK_* variables that are automatically populated with information about the current CI/deploy platform, git branch, commit, and inferred deployment environment. They are entirely opt-in — they only exist in your schema when you reference them.

Builtin variables are activated when you reference them via $VARLOCK_* in a value expression:

.env.schema
# @currentEnv=$VARLOCK_ENV
# ---
BUILD_TAG="build-$VARLOCK_COMMIT_SHA_SHORT"
DB_URL=if(
eq($VARLOCK_ENV, development),
postgres://localhost/myapp,
postgres://${VARLOCK_ENV}-db.example.com/myapp
)

If you want to include a builtin variable in your resolved env without referencing it from another item, just define it with an empty value — varlock will populate it automatically:

.env.schema
VARLOCK_BRANCH=
VARLOCK_COMMIT_SHA_SHORT=

You can also use VARLOCK_ENV as your environment flag with @currentEnv, which means you don’t need to create your own APP_ENV variable — Varlock will auto-detect the environment for you.

Type: string — one of development, preview, staging, production, test

The inferred deployment environment. Detection follows this priority:

  1. Test environment — detected from NODE_ENV=test, VITEST, JEST_WORKER_ID, or VITEST_POOL_ID
  2. Platform-provided — uses the platform’s own environment concept (e.g., Vercel’s VERCEL_ENV, Netlify’s CONTEXT)
  3. Branch inference — in CI, infers from branch name: main/master/production/prodproduction, staging/stage/develop/devstaging, qa/testtest, anything else → preview
  4. CI fallback — if in CI but no branch info is available, defaults to preview
  5. Local fallback — if not in CI, defaults to development
.env.schema
# @currentEnv=$VARLOCK_ENV
# ---
DB_HOST=if(forEnv(production), "prod-db.example.com", "localhost")
DB_NAME=myapp
DB_URL="postgres://$DB_HOST/$DB_NAME"

Type: string"true" or "false"

Whether the current process is running in a CI environment.

Type: string | undefined

The current git branch name, as reported by the CI platform. Undefined when not in CI or when the platform doesn’t expose branch info.

Type: string | undefined

The pull/merge request number, if the current build is for a PR. Undefined otherwise.

Type: string | undefined

The full git commit SHA.

Type: string | undefined

The short (7-character) git commit SHA.

Type: string | undefined

The name of the detected CI/deploy platform (e.g., "GitHub Actions", "Vercel", "Netlify CI").

Type: string | undefined

A URL linking to the current build or deploy in the CI platform’s UI.

Type: string | undefined

The repository name in owner/repo format.

Detection is built-in for these platforms (no configuration required):

  • GitHub Actions
  • GitLab CI
  • Vercel
  • Netlify
  • Cloudflare Pages / Workers
  • AWS CodeBuild
  • Azure Pipelines
  • Bitbucket Pipelines
  • Buildkite
  • CircleCI
  • Jenkins
  • Render
  • Travis CI
  • and many more

Not all platforms expose all fields. For example, some may not provide branch name or PR number.

CI/deploy platform detection is powered by @varlock/ci-env-info, which can also be used as a standalone package.