如何通过Azure CLI/PowerShell从现有Azure App Service下载源码并完成部署
Azure App Service 非Git方式 下载/部署操作命令参考
以下仅提供云侧操作对应的Azure CLI/PowerShell命令示例,本地源码修改、zip打包为本地操作可自行处理,所有方案均不涉及Git操作。
步骤1:下载现有App Service部署内容
前置要求
- Azure CLI 2.48及以上版本(低版本可执行
az upgrade升级) - 已通过
az login登录并切换到对应订阅:az account set --subscription <你的订阅ID>
Azure CLI 命令
az webapp content download --resource-group <替换为你的资源组名称> --name <替换为你的App Service名称> --file-path <本地保存zip的完整路径,比如D:\work\original-site.zip>
执行后会直接拉取App Service wwwroot目录下的所有部署文件,打包为zip保存到指定本地路径。
PowerShell 命令
(需安装最新Az PowerShell模块,可执行Install-Module -Name Az -Force -AllowClobber安装)
Save-AzWebAppPackage -ResourceGroupName <替换为你的资源组名称> -Name <替换为你的App Service名称> -OutputFile <本地保存zip的完整路径>
步骤4:部署前停止App Service
Azure CLI 命令
az webapp stop --resource-group <你的资源组名称> --name <你的App Service名称>
PowerShell 命令
Stop-AzWebApp -ResourceGroupName <你的资源组名称> -Name <你的App Service名称>
步骤5:部署本地修改后的zip包
Azure CLI 命令
az webapp deployment source config-zip --resource-group <你的资源组名称> --name <你的App Service名称> --src <本地修改后zip包的完整路径>
该命令为Azure原生zip部署方式,无需关联Git仓库,会直接覆盖wwwroot目录内容为zip包内的文件。
PowerShell 命令
Publish-AzWebApp -ResourceGroupName <你的资源组名称> -Name <你的App Service名称> -ArchivePath <本地修改后zip包的完整路径>
步骤6:部署完成后启动App Service
Azure CLI 命令
az webapp start --resource-group <你的资源组名称> --name <你的App Service名称>
PowerShell 命令
Start-AzWebApp -ResourceGroupName <你的资源组名称> -Name <你的App Service名称>
补充注意事项
- 本地打包zip时,确保修改后的文件直接位于zip根目录,不要嵌套额外的外层文件夹,避免部署后站点路径错误。
- 所有命令执行前需确认当前登录的账号拥有对应App Service的贡献者及以上权限。
内容的提问来源于stack exchange,提问作者user203687
相关产品推荐
相关产品推荐

