Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.compartment.dev/llms.txt

Use this file to discover all available pages before exploring further.

compartment variable is a subcommand group for managing the runtime environment variables that Compartment injects into your services. Variables can be scoped to the whole project, a specific environment, or a specific service within an environment. Sensitive variables are stored encrypted and their values are hidden in list and show output after they are set.

Sensitivity levels

Every variable has a sensitivity level:
  • plain — the value is visible in list and show output. Use this for non-secret configuration like feature flags or log levels.
  • sensitive — the value is stored encrypted and masked in output. Use this for secrets like API keys, database passwords, or tokens. Pass --sensitive when setting or importing to mark a variable as sensitive.

Scope

Variables are resolved from the narrowest scope outward. A variable set on a specific service overrides one set on the environment, which overrides one set on the project. Use --env and --service together to set a variable that applies only to one service in one environment.

Subcommands

Set or update a single variable. The value can be passed as a positional argument, read from standard input with --stdin, or entered interactively if neither is provided and the flag --sensitive is used.
compartment variable set <KEY> [value] [options]

Options

FlagTypeDefaultDescription
--project <name>stringProject slug. If omitted, read from compartment.yml.
--env <name>stringEnvironment name to scope the variable to.
--service <name>stringService name to scope the variable to.
--sensitivebooleanMark the variable as sensitive. Its value will be masked in all output after being set.
--stdinbooleanRead the value from standard input instead of a positional argument. Useful for piping secrets.
--output <format>text | jsontextOutput format.

Examples

Set a plain variable for the whole project
compartment variable set LOG_LEVEL debug --project my-app
Set a sensitive variable scoped to an environment
compartment variable set DATABASE_URL "postgres://..." --project my-app --env production --sensitive
Pipe a secret from a file into a sensitive variable
cat /run/secrets/api_key | compartment variable set API_KEY --project my-app --env production --sensitive --stdin
Removing a variable is immediate and irreversible. If the deleted variable was providing configuration to a running service, you may need to redeploy or rollback to restore a working state.
Variable changes take effect on the next deployment. Services that are already running do not pick up new or removed variables until the service is redeployed or restarted.