命令速查表-AZD必备命令


文档摘要

命令速查表 - AZD 必备命令 所有章节快速参考 课程主页: AZD 初学者指南 快速入门: 第1章: 基础与快速入门 AI 命令: 第2章: AI优先开发 高级内容: 第4章: 基础设施即代码 简介 这份全面的速查表按类别整理了最常用的 Azure Developer CLI 命令,并提供实用示例。非常适合在开发、故障排除以及日常操作中快速查阅 azd 项目相关内容。 学习目标 通过使用这份速查表,您将能够: 快速访问关键的 Azure Developer CLI 命令及其语法 按功能类别和使用场景理解命令组织方式 参考常见开发和部署场景的实用示例 访问故障排除命令以快速解决问题 高效找到高级配置和自定义选项 轻松定位环境管理和多环境工作流命令 学习成果

命令速查表 - AZD 必备命令

所有章节快速参考

简介

这份全面的速查表按类别整理了最常用的 Azure Developer CLI 命令,并提供实用示例。非常适合在开发、故障排除以及日常操作中快速查阅 azd 项目相关内容。

学习目标

通过使用这份速查表,您将能够:

  • 快速访问关键的 Azure Developer CLI 命令及其语法
  • 按功能类别和使用场景理解命令组织方式
  • 参考常见开发和部署场景的实用示例
  • 访问故障排除命令以快速解决问题
  • 高效找到高级配置和自定义选项
  • 轻松定位环境管理和多环境工作流命令

学习成果

通过定期参考这份速查表,您将能够:

  • 自信地执行 azd 命令,无需查阅完整文档
  • 使用适当的诊断命令快速解决常见问题
  • 高效管理多环境和部署场景
  • 根据需要应用高级 azd 功能和配置选项
  • 使用系统化的命令序列排查部署问题
  • 通过有效使用 azd 快捷方式和选项优化工作流

入门命令

身份验证

# Login to Azure (uses Azure CLI) az login # Check current account az account show # Set default subscription az account set --subscription "your-subscription-id" azd config set defaults.subscription "your-subscription-id"

项目初始化

# Browse available templates azd template list # Initialize from template azd init --template todo-nodejs-mongo azd init --template <template-name> # Initialize in current directory azd init . # Initialize with custom name azd init --template todo-nodejs-mongo my-awesome-app

核心部署命令

完整部署工作流

# Deploy everything (provision + deploy) azd up # Deploy with confirmation prompts disabled azd up --confirm-with-no-prompt # Deploy to specific environment azd up --environment production # Deploy with custom parameters azd up --parameter location=westus2

仅部署基础设施

# Provision Azure resources azd provision # Preview infrastructure changes (NEW) azd provision --preview # Shows a dry-run view of what resources would be created/modified/deleted # Similar to 'terraform plan' or 'bicep what-if' - safe to run, no changes applied # Provision with what-if analysis azd provision --what-if

仅部署应用程序

# Deploy application code azd deploy # Deploy specific service azd deploy --service web azd deploy --service api # Deploy all services azd deploy --all

构建与打包

# Build applications azd package # Build specific service azd package --service api

环境管理

环境操作

# List all environments azd env list # Create new environment azd env new development azd env new staging --location westus2 # Select environment azd env select production # Show current environment azd env show # Refresh environment state azd env refresh

环境变量

# Set environment variable azd env set API_KEY "your-secret-key" azd env set DEBUG true # Get environment variable azd env get API_KEY # List all environment variables azd env get-values # Remove environment variable azd env unset DEBUG

⚙️ 配置命令

全局配置

# List all configuration azd config list # Set global defaults azd config set defaults.location eastus2 azd config set defaults.subscription "sub-id" # Remove configuration azd config unset defaults.location # Reset all configuration azd config reset

项目配置

# Validate azure.yaml azd config validate # Show project information azd show # Get service endpoints azd show --output json

监控与日志

应用程序日志

# View logs from all services azd logs # View logs from specific service azd logs --service api # Follow logs in real-time azd logs --follow # View logs since specific time azd logs --since 1h azd logs --since "2024-01-01 10:00:00" # Filter logs by level azd logs --level error

监控

# Open Azure portal for monitoring azd monitor # Open Application Insights azd monitor --insights

️ 维护命令

清理

# Remove all Azure resources azd down # Force delete without confirmation azd down --force # Purge soft-deleted resources azd down --purge # Complete cleanup azd down --force --purge

更新

# Check for azd updates azd version --check-for-updates # Get current version azd version # Show system information azd info

高级命令

流水线与 CI/CD

# Configure GitHub Actions azd pipeline config # Configure Azure DevOps azd pipeline config --provider azdo # Show pipeline configuration azd pipeline show

基础设施管理

# Import existing resources azd infra import # Export infrastructure template azd infra export # Validate infrastructure azd infra validate # Infrastructure Preview & Planning (NEW) azd provision --preview # Simulates infrastructure provisioning without deploying # Analyzes Bicep/Terraform templates and shows: # - Resources to be added (green +) # - Resources to be modified (yellow ~) # - Resources to be deleted (red -) # Safe to run - no actual changes made to Azure environment

服务管理

# List all services azd service list # Show service details azd service show --service web # Restart service azd service restart --service api

快速工作流

开发工作流

# Start new project azd init --template todo-nodejs-mongo cd my-project # Deploy to development azd env new dev azd up # Make changes and redeploy azd deploy # View logs azd logs --follow

多环境工作流

# Set up environments azd env new dev azd env new staging azd env new production # Deploy to dev azd env select dev azd up # Test and promote to staging azd env select staging azd up # Deploy to production azd env select production azd up

故障排除工作流

# Enable debug mode export AZD_DEBUG=true # Check system info azd info # Validate configuration azd config validate # View detailed logs azd logs --level debug --since 1h # Check resource status azd show --output json

调试命令

调试信息

# Enable debug output export AZD_DEBUG=true azd <command> --debug # Disable telemetry for cleaner output export AZD_DISABLE_TELEMETRY=true # Get system information azd info # Check authentication status az account show

模板调试

# List available templates with details azd template list --output json # Show template information azd template show <template-name> # Validate template before init azd template validate <template-name>

文件与目录命令

项目结构

# Show current directory structure tree /f # Windows find . -type f # Linux/macOS # Navigate to azd project root cd $(azd root) # Show azd configuration directory echo $AZD_CONFIG_DIR # Usually ~/.azd

输出格式

JSON 输出

# Get JSON output for scripting azd show --output json azd env list --output json azd config list --output json # Parse with jq azd show --output json | jq '.services.web.endpoint' azd env get-values --output json | jq -r '.DATABASE_URL'

表格输出

# Format as table azd env list --output table azd service list --output table

常用命令组合

健康检查脚本

#!/bin/bash # Quick health check azd show azd env show azd logs --level error --since 10m

部署验证

#!/bin/bash # Pre-deployment validation azd config validate azd provision --preview # NEW: Preview changes before deploying az account show

环境比较

#!/bin/bash # Compare environments for env in dev staging production; do echo "=== $env ===" azd env select $env azd show --output json | jq '.services[].endpoint' done

资源清理脚本

#!/bin/bash # Clean up old environments azd env list | grep -E "(dev-|test-)" | while read env; do echo "Cleaning up $env" azd env select $env azd down --force --purge done

环境变量

常见环境变量

# Azure configuration export AZURE_SUBSCRIPTION_ID="your-subscription-id" export AZURE_LOCATION="eastus2" export AZURE_ENV_NAME="development" # AZD configuration export AZD_DEBUG=true export AZD_DISABLE_TELEMETRY=true export AZD_CONFIG_DIR="~/.azd" # Application configuration export NODE_ENV="production" export LOG_LEVEL="info"

紧急命令

快速修复

# Reset authentication az account clear az login # Force refresh environment azd env refresh --force # Restart all services azd service restart --all # Quick rollback azd deploy --rollback

恢复命令

# Recover from failed deployment azd provision --continue-on-error azd deploy --ignore-errors # Clean slate recovery azd down --force azd up --confirm-with-no-prompt

专业提示

快捷别名

# Add to your .bashrc or .zshrc alias azdup='azd up --confirm-with-no-prompt' alias azdl='azd logs --follow' alias azds='azd show --output json' alias azde='azd env'

功能快捷方式

# Quick environment switching azd-env() { azd env select $1 && azd show } # Quick deployment with logs azd-deploy-watch() { azd deploy --service $1 && azd logs --service $1 --follow } # Environment status azd-status() { echo "Current environment: $(azd env show --output json | jq -r '.name')" echo "Services:" azd show --output json | jq -r '.services | keys[]' }

帮助与文档

获取帮助

# General help azd --help azd help # Command-specific help azd up --help azd env --help azd config --help # Show version and build info azd version azd version --output json

文档链接

# Open documentation in browser azd docs # Show template documentation azd template show <template-name> --docs

提示: 收藏这份速查表,并使用 Ctrl+F 快速找到您需要的命令!

导航

免责声明
本文档使用AI翻译服务Co-op Translator进行翻译。尽管我们努力确保翻译的准确性,但请注意,自动翻译可能包含错误或不准确之处。原始语言的文档应被视为权威来源。对于重要信息,建议使用专业人工翻译。我们不对因使用此翻译而产生的任何误解或误读承担责任。


发布者: 作者: 转发
评论区 (0)
U