Skip to content

Environments ​

An environment is what a build is made for, Preview or Stable, and the set of variables that build receives. Reach for it when your Stable builds need production values and everything else must stay away from them.

Quick start ​

text
Project settings, Environment variables
  Key:   API_BASE_URL
  Scope: Stable

A variable with the Stable scope reaches only builds made for Stable. The same key with the Preview scope reaches builds made for Preview.

How it works ​

Two environments, and the channel decides. There are exactly two environments, and every build is made for one of them. A push to the Release branch named under Project settings, Deployment is made for Stable. When that field is empty, the repository's default branch is the Release branch. Every other push, a pull request build and a plain Rebuild under Builds are made for Preview. preview takes any build. stable and every channel you create take only a build made for Stable, so a channel you create never carries Preview values to its audience. A store submission takes a build made for Stable the same way. The Release branch is the one project setting that decides what a push build is made for.

Getting a Stable build. The release form at /releases/new and the submission page offer Rebuild for Stable · 1 build. The offer appears when the build you picked was made for Preview. Both track that build and arm the action when it lands. From a machine, POST /api/projects/{id}/builds/dispatch takes buildEnv, and so does the agent's extension_builds rebuild. See Builds.

Scoping a variable. A variable is set in Project settings, Environment variables with one of three scopes: all channels, Stable or Preview. An API base URL usually differs per environment, a public analytics key usually does not. Scope each accordingly instead of duplicating values.

The build carries its environment. The build is stamped with the environment it was made for, and the stamp travels with it. A Preview build released to stable or to a channel you created is refused:

text
409 BUILD_ENV_MISMATCH
This build was made for Preview, but the stable channel takes Stable builds.
Rebuild this commit for Stable (Builds, Rebuild), then release it.

See Release gates.

A release never re-runs a build. If a value must differ between Preview and Stable, the commit has to be built for Stable, not released into it.

Reading values at build time. Variables reach the build as process environment variables. Whatever the build inlines is readable in the shipped extension, so treat every value that reaches client code as public, whatever the environment.

DANGER

Do not put store credentials or signing keys in environment variables. Store credentials belong in Project settings, Store publishing, where the project holds them for submissions.

Reference ​

ChannelTakes
previewAny build
stableA build made for Stable
A channel you createA build made for Stable
ScopeStored asWhich builds receive the value
All channelsallEvery build of the project
StableproductionBuilds made for Stable
PreviewstagingBuilds made for Preview
RuleValue
Environment of a push buildStable on the Release branch, Preview on every other push and on every pull request
Key pattern^[A-Z0-9_]+$: uppercase letters, digits and underscores
Environment on the build recordbuildEnv, stored as production or staging
Release with a mismatched stampRefused with 409 BUILD_ENV_MISMATCH
Preview build of the commit Stable serves, by rebuild, by a push to another branch or by a check re-runRefused with 409 BUILD_ENV_SERVED; the record is keyed by commit and would change environment

When it fails ​

  • A release to stable is refused. The build was made for Preview: it came from a push to a branch other than the Release branch, from a pull request, or from a plain Rebuild under Builds. Start the release at /releases/new. It pauses on the refusal and offers Rebuild for Stable. The form tracks that build and arms Create release when it lands. See Release gates.
  • A store submission is refused the same way. A submission takes a build made for Stable. The submission page offers the same rebuild and arms the submit when the build lands.
  • A variable will not save. The key fails ^[A-Z0-9_]+$. Uppercase it and replace dashes and dots with underscores.
  • A value is missing from a build. Its scope does not cover the environment the build was made for. Check whether it sits in the other environment, or move it to all channels.
  • A secret shipped inside the extension. The build inlined it, and no environment scoping prevents that. Rotate the secret and move the work that needs it server side.

Next ​