Skip to content

feat: add variable import/export commands#857

Open
manwindersingh1712 wants to merge 2 commits intorailwayapp:masterfrom
manwindersingh1712:manwinder/variable-import-export
Open

feat: add variable import/export commands#857
manwindersingh1712 wants to merge 2 commits intorailwayapp:masterfrom
manwindersingh1712:manwinder/variable-import-export

Conversation

@manwindersingh1712
Copy link
Copy Markdown

Description

Adds bulk import/export functionality for environment variables, enabling easier CI/CD integration, backups, and bulk configuration management.

New Commands

railway variable import

Import environment variables from a .env or .json file.

# Import from .env file (auto-detected)
railway variable import --file .env.staging

# Import from JSON file
railway variable import --file backup.json

# Import to specific service/environment
railway variable import --file .env --service <my-service> --environment <production/staging/etc>

# Auto-accept all overwrites (non-interactive/CI mode)
railway variable import --file .env --yes

# Import without triggering deployments
railway variable import --file .env --skip-deploys

# JSON output
railway variable import --file .env --json

Features:

  • Auto-detects format by file extension (.json vs .env)
  • Interactive conflict resolution (prompts with [y/N/q] for existing keys)
  • Non-TTY mode skips conflicts with warning (use --yes to override)
  • Supports quoted values, escape sequences (\n, \t, \r, \"), comments, and empty lines

railway variable export

Export environment variables to a .env or .json file.

# Export to .env file
railway variable export --file .env.backup

# Export to JSON file
railway variable export --file backup.json

# Export from specific service/environment
railway variable export --file prod.env --service my-service --environment production

# JSON output to stdout
railway variable export --file backup.env --json

Features:

  • Auto-detects format by file extension
  • Properly escapes special characters for .env format
  • Pretty-printed JSON output

Supported File Formats

.env Format

# Basic key-value pairs
DATABASE_URL=postgres://localhost/mydb
API_KEY=secret123

# Double-quoted values with escape sequences
JSON_DATA="{\"key\": \"value\"}"
MULTILINE="line1\nline2\ttab"

# Single-quoted values (no escape processing)
LITERAL='no $pecial \processing'

# Empty values
EMPTY=

# Comments and empty lines are ignored
# This is a comment

JSON Format

{
  "DATABASE_URL": "postgres://localhost/mydb",
  "API_KEY": "secret123",
  "DEBUG": "true"
}

CI/CD Usage Example

# Export production variables for backup
railway variable export --file prod-backup.json --environment production

# Import variables to staging (non-interactive)
railway variable import --file prod-backup.json --environment staging --yes

# Or use --skip-deploys to set variables without triggering deploys
railway variable import --file .env.ci --yes --skip-deploys

Testing

All tests pass:

  • 9 CLI parsing tests for import/export commands
  • 18 unit tests for .env and JSON parsers
  • 135 total tests
cargo test

@manwindersingh1712 manwindersingh1712 changed the title Manwinder/variable import export feat: add variable import/export commands Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant