Run scripts with azd environment context

azd exec ./script.sh

Database migrations, setup automation, CI/CD workflows - with seamless access to Azure credentials and Key Vault secrets.

⚠️

Security Notice

IMPORTANT: azd exec executes scripts with full access to your Azure credentials and environment. Only run scripts you trust and have reviewed. Never pipe untrusted scripts from the internet.

Read Security Guidelines →

Everything You Need

🔧

Multiple Shell Support

Automatically detects and runs bash, sh, zsh, PowerShell, pwsh, and cmd scripts based on file extension or shebang.

🎯

Script Arguments

Pass arguments to your scripts seamlessly with the -- separator for clean parameter handling.

🌍

Full Azure Context

Access all azd environment variables including subscription, tenant, location, and custom variables.

📂

Working Directory Control

Execute scripts from any directory with the global --cwd flag for flexible automation.

🔄

Interactive Mode

Run scripts with interactive input support for prompts and user interaction.

🔐

Azure Key Vault Integration

Automatically resolves Key Vault references in environment variables, securely fetching secrets at runtime without hardcoding credentials.

Battle-Tested

Comprehensive security scanning with CodeQL and gosec (0 vulnerabilities). 86%+ test coverage.

Quick Start

1

Install Extension

Terminal window
# Install Azure Developer CLI
winget install microsoft.azd
# Enable extensions
azd config set alpha.extension.enabled on
# Add extension source
azd extension source add -n azd-exec -t url -l https://raw.githubusercontent.com/jongio/azd-exec/main/registry.json
# Install extension
azd extension install jongio.azd.exec
2

Verify Installation

Terminal window
azd exec version
3

Run Your Script

Terminal window
# Review the script first
cat ./run-migration.sh
# Then execute
azd exec ./run-migration.sh

Example Scripts

Bash Script

run-migration.sh
#!/bin/bash
echo "Running database migration for: $AZURE_ENV_NAME"
# Get database connection string from Azure SQL
CONN_STRING=$(az sql db show-connection-string \
--server "sql-$AZURE_ENV_NAME" \
--name "db-$AZURE_ENV_NAME" \
--client sqlcmd -o tsv)
# Run migration using sqlcmd or your migration tool
sqlcmd -S "sql-$AZURE_ENV_NAME.database.windows.net" \
-d "db-$AZURE_ENV_NAME" \
-G -i ./migrations/001_add_users_table.sql
echo "Migration completed!"

PowerShell Script

setup.ps1
Write-Host "Environment: $env:AZURE_ENV_NAME"
Write-Host "Resource Group: $env:AZURE_RESOURCE_GROUP"
# Your setup logic here

See more examples →

Ready to get started?

Install azd exec and start running your scripts with Azure context.

Get Started Now