Environment Variables
Ahoy can load environment variables from files before running your commands, keeping configuration and secrets out of your YAML.
A simple example v2.3.0+
Section titled “A simple example ”Create a .env file alongside your .ahoy.yml:
DB_USER=rootDB_PASS=secretDB_NAME=myappReference it in your config:
ahoyapi: v2
env: .env
commands: db: usage: Connect to the database cmd: mysql -u$DB_USER -p$DB_PASS $DB_NAMEThe path is relative to the .ahoy.yml file, not your working directory.
Global and per-command files
Section titled “Global and per-command files”The top-level env applies to every command. Individual commands can also specify their own env, which layers on top:
ahoyapi: v2
env: .env # Loaded for every command
commands: deploy: usage: Deploy the application env: .env.deploy # Also loaded for this command only cmd: ./deploy.shMultiple files v2.5.0+
Section titled “Multiple files ”Both global and per-command env fields accept an array. Files are loaded in order - later files override earlier ones:
ahoyapi: v2
env: - .env.base - .env.local # Overrides .env.base
commands: deploy: env: - .env.deploy - .env.staging cmd: ./deploy.sh stagingMissing files are silently skipped - no error.
Precedence
Section titled “Precedence”From lowest to highest:
- Your shell’s existing environment
- Global env files (in order)
- Command-specific env files (in order)
Runtime variables v3
Section titled “Runtime variables ”Ahoy automatically injects two variables into every command:
| Variable | Value |
|---|---|
AHOY_COMMAND_NAME |
The name of the command being run |
AHOY_CMD |
Path to the ahoy binary |
These are useful for scripts that call other ahoy commands, or need to know their own name.
Keep secrets out of version control
Section titled “Keep secrets out of version control”Add your real .env files to .gitignore and commit a .env.example with placeholder values:
.env.env.local.env.secrets# .env.example - safe to commitDB_USER=your_usernameDB_PASS=your_passwordDB_NAME=your_databaseFor the complete format specification and precedence details, see the Environment Reference.