Environment Variables
Set environment variables directly in your invowkfile. These are available to your scripts during execution.
Basic Usage
{
name: "build"
env: {
vars: {
NODE_ENV: "production"
API_URL: "https://api.example.com"
DEBUG: "false"
}
}
implementations: [{
script: {content: """
echo "Building for $NODE_ENV"
echo "API: $API_URL (debug: $DEBUG)"
"""}
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}]
}]
}
Variable Syntax
Variables are key-value string pairs:
vars: {
// Simple values
NAME: "value"
// Numbers (still strings in shell)
PORT: "3000"
TIMEOUT: "30"
// Boolean-like (strings "true"/"false")
DEBUG: "true"
VERBOSE: "false"
// Paths
CONFIG_PATH: "/etc/myapp/config.yaml"
OUTPUT_DIR: "./dist"
// URLs
API_URL: "https://api.example.com"
}
All values are strings. The shell interprets them as needed.
Literal Values and Shell Expansion
Values in env.vars are injected verbatim as literal strings without expanding ${VAR} references or $(...) command substitutions. When you need variable defaults, concatenation, or command substitution, evaluate them inside your script where the shell runs:
{
name: "info"
env: {
vars: {
PROJECT_NAME: "myapp"
DEFAULT_LOG_LEVEL: "info"
}
}
implementations: [{
script: {content: """
# Expand variables inside the script (not in env.vars)
HOME_CONFIG="${HOME}/.config/${PROJECT_NAME}"
EFFECTIVE_LOG_LEVEL="${LOG_LEVEL:-$DEFAULT_LOG_LEVEL}"
echo "Config: $HOME_CONFIG (log: $EFFECTIVE_LOG_LEVEL)"
"""}
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}]
}]
}
Scope Levels
Root Level
Available to all commands:
env: {
vars: {
PROJECT_NAME: "myproject"
VERSION: "1.0.0"
}
}
cmds: [
{
name: "build"
// Gets PROJECT_NAME and VERSION
implementations: [...]
},
{
name: "deploy"
// Also gets PROJECT_NAME and VERSION
implementations: [...]
}
]
Command Level
Available to specific command:
{
name: "build"
env: {
vars: {
BUILD_MODE: "release"
}
}
implementations: [...]
}
Implementation Level
Available to specific implementation:
{
name: "build"
implementations: [
{
script: {content: "npm run build"}
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}, {name: "windows"}]
env: {
vars: {
NODE_ENV: "production"
}
}
},
{
script: {content: "go build ./..."}
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}, {name: "windows"}]
env: {
vars: {
CGO_ENABLED: "0"
}
}
}
]
}
Platform Level
Per-platform variables:
// Platform-specific env requires separate implementations
implementations: [
{
script: {content: "echo $PLATFORM_CONFIG"}
runtimes: [{name: "native"}]
platforms: [{name: "linux"}]
env: {
vars: {
PLATFORM_CONFIG: "/etc/myapp"
PLATFORM_NAME: "Linux"
}
}
},
{
script: {content: "echo $PLATFORM_CONFIG"}
runtimes: [{name: "native"}]
platforms: [{name: "macos"}]
env: {
vars: {
PLATFORM_CONFIG: "/usr/local/etc/myapp"
PLATFORM_NAME: "macOS"
}
}
},
{
script: {content: "echo %PLATFORM_CONFIG%"}
runtimes: [{name: "native"}]
platforms: [{name: "windows"}]
env: {
vars: {
PLATFORM_CONFIG: "%APPDATA%\\myapp"
PLATFORM_NAME: "Windows"
}
}
}
]
Combined with Files
Variables override values from env files:
env: {
files: [".env"] // Loaded first
vars: {
// These override .env values
OVERRIDE: "from-invowkfile"
}
}
CLI Override
Override at runtime:
# Single variable
invowk cmd build --ivk-env-var NODE_ENV=development
# Multiple variables
invowk cmd build --ivk-env-var NODE_ENV=dev --ivk-env-var DEBUG=true --ivk-env-var PORT=8080
CLI variables have the highest priority.
Real-World Examples
Build Configuration
{
name: "build"
env: {
vars: {
NODE_ENV: "production"
BUILD_TARGET: "es2020"
SOURCEMAP: "false"
}
}
implementations: [{
script: {content: "npm run build"}
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}, {name: "windows"}]
}]
}
API Configuration
{
name: "start"
env: {
vars: {
API_HOST: "0.0.0.0"
API_PORT: "3000"
API_PREFIX: "/api/v1"
CORS_ORIGIN: "*"
}
}
implementations: [{
script: {content: "go run ./cmd/server"}
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}, {name: "windows"}]
}]
}
Dynamic Values
{
name: "release"
env: {
vars: {
// Static configuration lives in env.vars
APP_NAME: "myapp"
}
}
implementations: [{
script: {content: """
# Compute dynamic values inside the script
GIT_SHA="$(git rev-parse --short HEAD)"
GIT_BRANCH="$(git branch --show-current)"
BUILD_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
BUILD_ID="${GIT_BRANCH}-${GIT_SHA}"
echo "Building $APP_NAME ($BUILD_ID) at $BUILD_TIME"
go build -ldflags="-X main.version=$BUILD_ID" ./...
"""}
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}]
}]
}
Database Configuration
{
name: "db migrate"
env: {
vars: {
DB_HOST: "localhost"
DB_PORT: "5432"
DB_NAME: "myapp"
DB_USER: "postgres"
}
}
implementations: [{
script: {content: """
DATABASE_URL="postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}"
migrate -database "$DATABASE_URL" up
"""}
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}]
}]
}
Container Environment
Variables are passed into containers:
{
name: "build"
env: {
vars: {
TARGET_OS: "linux"
TARGET_ARCH: "amd64"
BUILD_MODE: "release"
}
}
implementations: [{
script: {content: "echo $TARGET_OS/$TARGET_ARCH in $BUILD_MODE mode"}
runtimes: [{name: "container", image: "debian:stable-slim"}]
platforms: [{name: "linux"}]
}]
}
Best Practices
- Keep
env.varsliteral: Apply${VAR:-default}fallbacks insidescriptwhere the shell expands them - Keep secrets out: Don't hardcode secrets; use env files or external secrets
- Document variables: Add comments explaining each variable
- Use consistent naming:
UPPER_SNAKE_CASEconvention - Scope appropriately: Root for shared, command for specific
Next Steps
- Env Files - Load from .env files
- Precedence - Understand override order