从 GitHub 使用连续部署创建 Web 应用

此示例脚本使用其相关资源,在应用服务中创建 Web 应用,并在 Git 存储库中设置连续部署。 有关不进行连续部署的 GitHub 部署,请参阅从 GitHub 创建 Web 应用并部署代码

必要时,请使用 Azure PowerShell 指南中的说明安装 Azure PowerShell,并运行 Connect-AzAccount -Environment AzureChinaCloud 创建与 Azure 的连接。 同时,请确保:

示例脚本

注意

建议使用 Azure Az PowerShell 模块与 Azure 交互。 请参阅安装 Azure PowerShell 以开始使用。 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 Az

$gitrepo="<replace-with-URL-of-your-own-GitHub-repo>"
$gittoken="<replace-with-a-GitHub-access-token>"
$webappname="mywebapp$(Get-Random)"
$location="China North"

# Create a resource group.
New-AzResourceGroup -Name myResourceGroup -Location $location

# Create an App Service plan in Free tier.
New-AzAppServicePlan -Name $webappname -Location $location `
-ResourceGroupName myResourceGroup -Tier Free

# Create a web app.
New-AzWebApp -Name $webappname -Location $location -AppServicePlan $webappname `
-ResourceGroupName myResourceGroup

# SET GitHub
$PropertiesObject = @{
	token = $gittoken;
}
Set-AzResource -PropertyObject $PropertiesObject `
-ResourceId /providers/Microsoft.Web/sourcecontrols/GitHub -ApiVersion 2015-08-01 -Force

# Configure GitHub deployment from your GitHub repo and deploy once.
$PropertiesObject = @{
    repoUrl = "$gitrepo";
    branch = "master";
}
Set-AzResource -PropertyObject $PropertiesObject -ResourceGroupName myResourceGroup `
-ResourceType Microsoft.Web/sites/sourcecontrols -ResourceName $webappname/web `
-ApiVersion 2015-08-01 -Force

清理部署

运行脚本示例后,可以使用以下命令删除资源组、Web 应用以及所有相关资源。

Remove-AzResourceGroup -Name myResourceGroup -Force

脚本说明

此脚本使用以下命令。 表中的每条命令均链接到特定于命令的文档。

命令 注释
New-AzResourceGroup 创建用于存储所有资源的资源组。
New-AzAppServicePlan 创建应用服务计划。
New-AzWebApp 创建 Web 应用。
Set-AzResource 修改资源组中的资源。

后续步骤

有关 Azure PowerShell 模块的详细信息,请参阅 Azure PowerShell 文档

可以在 Azure PowerShell 示例中找到 Azure 应用服务 Web 应用的其他 Azure Powershell 示例。