Getting Started
Follow these steps to install azd exec and run your first script with Azure context.
Prerequisites
Before installing azd exec, make sure you have:
- Azure Developer CLI (azd) installed on your system
- Azure subscription and appropriate permissions
- Basic knowledge of shell scripting (bash or PowerShell)
If you don't have azd installed, visit the official installation guide.
Install azd exec
Install the azd exec extension using the following commands for your platform:
# Install Azure Developer CLIwinget install microsoft.azd
# Enable extensionsazd config set alpha.extension.enabled on
# Add extension sourceazd extension source add -n azd-exec -t url -l https://raw.githubusercontent.com/jongio/azd-exec/main/registry.json
# Install extensionazd extension install jongio.azd.exec# Install Azure Developer CLIbrew tap azure/azd && brew install azd
# Enable extensionsazd config set alpha.extension.enabled on
# Add extension sourceazd extension source add -n azd-exec -t url -l https://raw.githubusercontent.com/jongio/azd-exec/main/registry.json
# Install extensionazd extension install jongio.azd.exec# Install Azure Developer CLIcurl -fsSL https://aka.ms/install-azd.sh | bash
# Enable extensionsazd config set alpha.extension.enabled on
# Add extension sourceazd extension source add -n azd-exec -t url -l https://raw.githubusercontent.com/jongio/azd-exec/main/registry.json
# Install extensionazd extension install jongio.azd.execVerify Installation
Confirm that azd exec is installed correctly:
azd exec versionYou should see output similar to:
azd exec version 0.1.0Run Your First Script
Create a simple script to test azd exec:
For Bash/Linux/macOS
# Create a test scriptcat > test-script.sh << 'EOF'#!/bin/bashecho "Azure Environment: $AZURE_ENV_NAME"echo "Subscription: $AZURE_SUBSCRIPTION_ID"echo "Location: $AZURE_LOCATION"EOF
# Make it executablechmod +x test-script.sh
# Review the scriptcat test-script.sh
# Execute with azd execazd exec ./test-script.shFor PowerShell/Windows
# Create a test script@'Write-Host "Azure Environment: $env:AZURE_ENV_NAME"Write-Host "Subscription: $env:AZURE_SUBSCRIPTION_ID"Write-Host "Location: $env:AZURE_LOCATION"'@ | Out-File test-script.ps1
# Review the scriptGet-Content test-script.ps1
# Execute with azd execazd exec ./test-script.ps1Security Best Practices
Always Follow These Practices:
- ✅ Review scripts before running them
- ✅ Use HTTPS for any script downloads
- ✅ Verify the source of scripts from documentation or trusted repositories
- ✅ Store secrets in Azure Key Vault, not environment variables
- ❌ Never pipe untrusted scripts:
curl http://site.com/script.sh | azd exec - - ❌ Don't run scripts from unknown or untrusted sources
For comprehensive security information, see the Security Guidelines.
Common Commands
Basic Execution
azd exec ./my-script.shPass Arguments
azd exec ./build.sh --verbose --config releaseSpecify Shell
azd exec --shell pwsh ./deploy.ps1Set Working Directory
azd exec --cwd /path/to/project ./setup.shInteractive Mode
azd exec --interactive ./interactive-setup.shAzure Key Vault Integration
azd exec automatically resolves Azure Key Vault references in environment variables, allowing you to securely store and access secrets without hardcoding them.
Supported Reference Formats
Use any of these formats to reference Key Vault secrets:
# Format 1: SecretUri@Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/my-secret)@Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/my-secret/abc123)
# Format 2: VaultName and SecretName@Microsoft.KeyVault(VaultName=myvault;SecretName=my-secret)@Microsoft.KeyVault(VaultName=myvault;SecretName=my-secret;SecretVersion=abc123)
# Format 3: azd akvs URI (used internally by azd)akvs://c3b3091e-400e-43a7-8ee5-e6e8cefdbebf/myvault/my-secretakvs://c3b3091e-400e-43a7-8ee5-e6e8cefdbebf/myvault/my-secret/abc123Quick Example
1. Store a secret in Azure Key Vault:
az keyvault secret set --vault-name myvault --name database-password --value "SuperSecret123!"2. Set environment variable with Key Vault reference:
azd env set-secret DATABASE_PASSWORD3. Use in your script:
#!/bin/bashecho "Connecting to database..."# DATABASE_PASSWORD is automatically resolved to the actual secret valuemysql -u admin -p"$DATABASE_PASSWORD" -h myserver.mysql.database.azure.com4. Run the script:
azd exec ./deploy.shHow It Works
- azd exec scans environment variables for Key Vault references
- Uses Azure DefaultAzureCredential (same authentication as azd)
- Fetches secret values from Key Vault before running your script
- Passes resolved values to your script securely
- If resolution fails, warns but continues with original values
Error Handling
By default, if Key Vault resolution fails (e.g., secret not found, no access), azd exec displays a warning but continues.
To fail-fast on Key Vault errors, use the --stop-on-keyvault-error flag:
azd exec --stop-on-keyvault-error ./script.shFor more examples, see the Key Vault examples section.