envfly push

Add or update environment variables in your EnvFly project.

Usage

envfly push <environment> <variable> <value> [options]
envfly push <environment> --file <file> [options]
envfly push <environment> --from-env [options]

Description

The push command adds or updates environment variables in a specific environment. Variables are automatically encrypted and stored securely. This command is essential for:
  • Initial Setup: Adding variables when setting up new environments
  • Updates: Modifying existing variables with new values
  • Bulk Operations: Importing multiple variables from files
  • CI/CD: Automating environment variable management

Arguments

Options

Examples

Basic Push

# Add a single variable
$ envfly push development DATABASE_URL="postgresql://localhost:5432/dev"
 Pushed DATABASE_URL to development environment

# Add multiple variables
$ envfly push development API_KEY="dev_key_123"
$ envfly push development DEBUG="true"
$ envfly push development PORT="3000"
 Pushed API_KEY to development environment
 Pushed DEBUG to development environment
 Pushed PORT to development environment

Push from File

# From .env file
$ cat .env
DATABASE_URL=postgresql://localhost:5432/dev
API_KEY=dev_key_123
DEBUG=true
PORT=3000

$ envfly push development --file .env
 Pushed 4 variables to development environment

Push from JSON

# From JSON file
$ cat config.json
{
  "DATABASE_URL": "postgresql://localhost:5432/dev",
  "API_KEY": "dev_key_123",
  "DEBUG": true,
  "PORT": 3000
}

$ envfly push development --file config.json
 Pushed 4 variables to development environment

Push from YAML

# From YAML file
$ cat variables.yaml
DATABASE_URL: postgresql://localhost:5432/dev
API_KEY: dev_key_123
DEBUG: true
PORT: 3000

$ envfly push development --file variables.yaml
 Pushed 4 variables to development environment

Push from Environment

# Set environment variables
$ export DATABASE_URL="postgresql://localhost:5432/dev"
$ export API_KEY="dev_key_123"
$ export DEBUG="true"

# Push from current environment
$ envfly push development --from-env
 Pushed 3 variables to development environment

With Descriptions

$ envfly push production DATABASE_URL="postgresql://prod:5432/db" --description "Production PostgreSQL database"
$ envfly push production API_KEY="prod_key_456" --description "Production API key for external services"
$ envfly push production LOG_LEVEL="info" --description "Production logging level"
 Pushed DATABASE_URL to production environment
 Pushed API_KEY to production environment
 Pushed LOG_LEVEL to production environment

Dry Run

$ envfly push production API_KEY="new_key" --dry-run
🔍 Dry run - would push:
  API_KEY: "new_key" (encrypted)
  Environment: production
  Description: (none)

Force Overwrite

$ envfly push production API_KEY="new_key" --force
⚠️  Overwriting existing variable: API_KEY
 Pushed API_KEY to production environment

File Formats

.env Format

# .env file
DATABASE_URL=postgresql://localhost:5432/dev
API_KEY=dev_key_123
DEBUG=true
PORT=3000
NODE_ENV=development

JSON Format

{
  "DATABASE_URL": "postgresql://localhost:5432/dev",
  "API_KEY": "dev_key_123",
  "DEBUG": true,
  "PORT": 3000,
  "NODE_ENV": "development"
}

YAML Format

DATABASE_URL: postgresql://localhost:5432/dev
API_KEY: dev_key_123
DEBUG: true
PORT: 3000
NODE_ENV: development

Use Cases

Integration Examples

CI/CD Pipeline

# .github/workflows/deploy.yml
name: Deploy
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: "18"

      - name: Install EnvFly CLI
        run: npm install -g envfly-cli

      - name: Login to EnvFly
        run: |
          echo ${{ secrets.ENVFLY_API_KEY }} | envfly login

      - name: Push Production Variables
        run: |
          envfly push production DATABASE_URL="${{ secrets.DATABASE_URL }}"
          envfly push production API_KEY="${{ secrets.API_KEY }}"
          envfly push production LOG_LEVEL="info"

      - name: Deploy Application
        run: |
          envfly pull production
          npm run deploy

Scripting

#!/bin/bash
# setup-environments.sh

echo "Setting up development environment..."

# Development variables
envfly push development DATABASE_URL="postgresql://localhost:5432/dev" --description "Local development database"
envfly push development API_KEY="dev_key_123" --description "Development API key"
envfly push development DEBUG="true" --description "Enable debug mode"
envfly push development PORT="3000" --description "Application port"

echo "Setting up staging environment..."

# Staging variables
envfly push staging DATABASE_URL="postgresql://staging:5432/staging" --description "Staging database"
envfly push staging API_KEY="staging_key_456" --description "Staging API key"
envfly push staging DEBUG="false" --description "Disable debug mode"
envfly push staging PORT="3000" --description "Application port"

echo "Environments setup complete!"

Team Collaboration

# Team lead setting up shared variables
envfly push development SHARED_API_URL="https://api.company.com" --description "Shared API endpoint"
envfly push development TEAM_EMAIL="team@company.com" --description "Team contact email"

# Developer adding personal variables
envfly push development PERSONAL_API_KEY="my_dev_key" --description "Personal development API key"

Error Handling

Best Practices