Variables let you pass runtime configuration to your services without baking values into your repository. You manage them through the Compartment CLI and the platform injects them as environment variables when your service starts. Variables are never stored inDocumentation 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.yml — keeping runtime values separate from build-time configuration is a deliberate design choice.
Variable types
Every variable has a sensitivity that controls how Compartment stores and displays its value:| Sensitivity | Description |
|---|---|
plain | Value is readable after it is set. |
sensitive | Value is write-only. Once set, Compartment never returns the value in API responses or CLI output. |
sensitive for passwords, tokens, API keys, and any other value that should not be readable after it is written.
Variable scopes
Every variable also has a scope type that determines which services receive it:| Scope type | Description |
|---|---|
environment | Project-wide. All services in the environment receive the variable unless a service-level variable with the same key overrides it. |
service | Service-specific. Only the named service receives the variable. A service-level variable overrides any environment-level variable with the same key. |
Key name rules
Variable key names must satisfy these rules:- Start with a letter (
A–Z,a–z) or an underscore (_) - Contain only letters, digits (
0–9), and underscores - Must not start with
COMPARTMENT_— that prefix is reserved for Compartment-managed runtime metadata
Managing variables with the CLI
Set a variable
my-app. Compartment prompts you to select an environment if your project has more than one.
To target a specific service scope, add the --service flag:
List variables
Show a variable
valueHidden will be true in the response.
Import variables from a file
KEY=VALUE pair per line.
To import into a specific service scope:
Duplicate key names within a single import file are not allowed. Compartment will reject the import if it finds the same key more than once.
Remove a variable
--service:
Exposing variables during the build
Variables are runtime values by default. To expose a variable’s value during the build step (for example, a public API URL needed at compile time), list its key name in thebuild.env field of your service config in compartment.yml:
build.env, but use this carefully — build logs may reveal values that appear in compilation output.
Inheritance example
Given:- Environment variable
LOG_LEVEL=info - Service variable
LOG_LEVEL=debugon theapiservice
web service receives LOG_LEVEL=info (inherited from the environment scope). The api service receives LOG_LEVEL=debug (its service-level value overrides the inherited one).