持续部署到 Azure 应用服务Continuous deployment to Azure App Service

本文展示了如何为 Azure 应用服务配置持续部署。This article shows you how to configure continuous deployment for Azure App Service. 应用服务可以使用 BitBucket、GitHub 和 Azure DevOps Services 实现持续部署,方法是从上述服务之一中的现有存储库拉取最新的更新。App Service enables continuous deployment from BitBucket, GitHub, and Azure DevOps Services by pulling in the most recent updates from your existing repository in one of these services.

若要了解如何通过 Azure 门户中未列出的云存储库(如 GitLab)手动配置连续部署,请参阅使用手动步骤设置连续部署To find out how to configure continuous deployment manually from a cloud repository not listed by the Azure Portal (such as GitLab), see Setting up continuous deployment using manual steps.

准备存储库Prepare your repository

若要从 Azure 应用服务 Kudu 生成服务器获取自动生成,请确保项目中存储库根路径具有正确的文件。To get automatic builds from Azure App Service Kudu build server, make sure that your repository root has the correct files in your project.

运行时Runtime 根目录文件Root directory files
ASP.NET(仅限 Windows)ASP.NET (Windows only) *.sln*.csprojdefault.aspx*.sln, *.csproj, or default.aspx
ASP.NET CoreASP.NET Core *.sln*.csproj*.sln or *.csproj
PHPPHP index.php index.php
Ruby(仅限 Linux)Ruby (Linux only) Gemfile Gemfile
Node.jsNode.js server.js、app.js 或具有启动脚本的 package.json server.js, app.js, or package.json with a start script
PythonPython *.pyrequirements.txtruntime.txt*.py, requirements.txt, or runtime.txt
HTMLHTML default.htm、default.html、default.asp、index.htm、index.html 或 iisstart.htm default.htm, default.html, default.asp, index.htm, index.html, or iisstart.htm
Web 作业WebJobs App_Data/jobs/continuous(适用于连续的 WebJobs)或 App_Data/jobs/triggered(适用于触发的 WebJobs)下的 <job_name>/run.<extension> 。<job_name>/run.<extension> under App_Data/jobs/continuous for continuous WebJobs, or App_Data/jobs/triggered for triggered WebJobs. 有关详细信息,请参阅 Kudu WebJobs 文档For more information, see Kudu WebJobs documentation.
函数Functions 请参阅 Azure Functions 的连续部署See Continuous deployment for Azure Functions.

要自定义部署,可以在存储库根路径中添加 .deployment 文件 。To customize your deployment, include a .deployment file in the repository root. 有关详细信息,请参阅自定义部署自定义部署脚本For more information, see Customize deployments and Custom deployment script.

Note

如果在 Visual Studio 中进行开发,让 Visual Studio 创建存储库If you develop in Visual Studio, let Visual Studio create a repository for you. 该项目可立即通过 Git 进行部署。The project is immediately ready to be deployed by using Git.

将准备好的存储库发布到受支持的服务之一。Publish your prepared repository to one of the supported services. 要深入了解如何将项目发布到这些服务,请参阅创建存储库 (GitHub)创建存储库 (BitBucket)Azure DevOps Services 入门For more information on publishing your project to these services, see Create a repo (GitHub), Create a repo (BitBucket), and Get started with Azure DevOps Services.

从 GitHub 持续部署Deploy continuously from GitHub

若要使用 GitHub 实现持续部署,请在 Azure 门户中导航至你的应用服务应用页。To enable continuous deployment with GitHub, navigate to your App Service app page in the Azure portal.

在左侧菜单中,单击“部署中心” > “GitHub” > “授权”。In the left menu, click Deployment Center > GitHub > Authorize. 按照授权提示进行操作。Follow the authorization prompts.

只需要通过 GitHub 授权一次。You only need to authorize with GitHub once. 如果已获得授权,只需单击“继续”即可。If you're already authorized, just click Continue. 可以通过单击“更改帐户”来更改已获得授权的 GitHub 帐户。You can change the authorized GitHub account by clicking Change account.

在“生成提供程序”页面中,选择生成提供程序并单击 >“继续”。In the Build provider page, choose the build provider and click > Continue.

选项 1:使用应用服务 Kudu 生成服务器Option 1: use App Service Kudu build server

在“配置”页面中,选择要从中进行持续部署的组织、存储库和分支。In the Configure page, select the organization, repository, and branch from which you want to deploy continuously. 完成后,单击“继续”。When finished, click Continue.

选项 2:使用 Azure DevOps Services 持续交付Option 2: use Azure DevOps Services continuous delivery

Note

要让应用服务在 Azure DevOps Services 组织中创建必要的 Azure 管道,Azure 帐户必须在 Azure 订阅中具有“所有者”角色。For App Service to create the necessary Azure Pipelines in your Azure DevOps Services organization, your Azure account must have the role of Owner in your Azure subscription.

在“配置”页面中,在“代码”部分中,选择要从中进行持续部署的组织、存储库和分支。In the Configure page, in the Code section, select the organization, repository, and branch from which you want to deploy continuously. 完成后,单击“继续”。When finished, click Continue.

在“配置”页中的“生成”部分,配置新的 Azure DevOps Services 组织,或指定现有组织。In the Configure page, in the Build section, configure a new Azure DevOps Services organization or specify an existing organization. 完成后,单击“继续”。When finished, click Continue.

Note

如果要使用未列出的现有 Azure DevOps Services 组织,则需要将 Azure DevOps Services 组织链接到 Azure 订阅If you want to use an existing Azure DevOps Services organization that is not listed, you need to link the Azure DevOps Services organization to your Azure subscription.

在“测试”页面中,选择是否要启用负载测试,然后单击“继续”。In the Test page, choose whether to enable load tests, then click Continue.

根据应用服务计划的定价层,可能还会看到“部署到过渡环境”页。Depending on the pricing tier of your App Service plan, you may also see a Deploy to staging page. 选择是否要启用部署槽位,然后单击“继续”。Choose whether to enable deployment slots, then click Continue.

完成配置Finish configuration

在“摘要”页中,确认选项,然后单击“完成”。In the Summary page, verify your options and click Finish.

在配置完成后,选定存储库中的新提交将持续部署到应用服务应用。When configuration completes, new commits in the selected repository are deployed continuously into your App Service app.

从 BitBucket 持续部署Deploy continuously from BitBucket

若要使用 BitBucket 实现持续部署,请在 Azure 门户中导航至你的应用服务应用页。To enable continuous deployment with BitBucket, navigate to your App Service app page in the Azure portal.

在左侧菜单中,单击“部署中心” > “BitBucket” > “授权”。In the left menu, click Deployment Center > BitBucket > Authorize. 按照授权提示进行操作。Follow the authorization prompts.

只需要通过 BitBucket 授权一次。You only need to authorize with BitBucket once. 如果已获得授权,只需单击“继续”即可。If you're already authorized, just click Continue. 可以通过单击“更改帐户”来更改已获得授权的 BitBucket 帐户。You can change the authorized BitBucket account by clicking Change account.

在“配置”页面中,选择要从中进行持续部署的存储库和分支。In the Configure page, select the repository and branch from which you want to deploy continuously. 完成后,单击“继续”。When finished, click Continue.

在“摘要”页中,确认选项,然后单击“完成”。In the Summary page, verify your options and click Finish.

在配置完成后,选定存储库中的新提交将持续部署到应用服务应用。When configuration completes, new commits in the selected repository are deployed continuously into your App Service app.

从 Azure DevOps Services 持续部署Deploy continuously from Azure DevOps Services

若要使用 Azure DevOps Services 实现持续部署,请在 Azure 门户中导航到自己的“应用服务”应用页。To enable continuous deployment with Azure DevOps Services, navigate to your App Service app page in the Azure portal.

在左侧菜单中,单击“部署中心” > “Azure DevOps Services” > “继续”。In the left menu, click Deployment Center > Azure DevOps Services > Continue.

在“生成提供程序”页面中,选择生成提供程序并单击 >“继续”。In the Build provider page, choose the build provider and click > Continue.

选项 1:使用应用服务 Kudu 生成服务器Option 1: use App Service Kudu build server

在“配置”页中,选择要从中进行持续部署的 Azure DevOps Services 组织、项目、存储库和分支。In the Configure page, select the Azure DevOps Services organization, project, repository, and branch from which you want to deploy continuously. 完成后,单击“继续”。When finished, click Continue.

选项 2:使用 Azure DevOps Services 持续交付Option 2: use Azure DevOps Services continuous delivery

Note

要让应用服务在 Azure DevOps Services 组织中创建必要的 Azure 管道,Azure 帐户必须在 Azure 订阅中具有“所有者”角色。For App Service to create the necessary Azure Pipelines in your Azure DevOps Services organization, your Azure account must have the role of Owner in your Azure subscription.

在“配置”页中的“代码”部分,选择要从中进行持续部署的 Azure DevOps Services 组织、项目、存储库和分支。In the Configure page, in the Code section, select the Azure DevOps Services organization, project, repository, and branch from which you want to deploy continuously. 完成后,单击“继续”。When finished, click Continue.

Note

如果要使用未列出的现有 Azure DevOps Services 组织,则需要将 Azure DevOps Services 组织链接到 Azure 订阅If you want to use an existing Azure DevOps Services organization that is not listed, you need to link the Azure DevOps Services organization to your Azure subscription.

在“配置”页中的“生成”部分,指定 Azure DevOps Services 在为选定的存储库运行生成任务时应当使用的语言框架。In the Configure page, in the Build section, specify the language framework that Azure DevOps Services should use to run the build tasks for your selected repository. 完成后,单击“继续”。When finished, click Continue.

在“测试”页面中,选择是否要启用负载测试,然后单击“继续”。In the Test page, choose whether to enable load tests, then click Continue.

根据应用服务计划的定价层,可能还会看到“部署到过渡环境”页。Depending on the pricing tier of your App Service plan, you may also see a Deploy to staging page. 选择是否要启用部署槽位,然后单击“继续”。Choose whether to enable deployment slots, then click Continue.

完成配置Finish configuration

在“摘要”页中,确认选项,然后单击“完成”。In the Summary page, verify your options and click Finish.

在配置完成后,选定存储库中的新提交将持续部署到应用服务应用。When configuration completes, new commits in the selected repository are deployed continuously into your App Service app.

禁用持续部署Disable continuous deployment

若要禁用持续部署,请在 Azure 门户中导航至你的应用服务应用页。To disable continuous deployment, navigate to your App Service app page in the Azure portal.

在左侧菜单中,单击“部署中心” > “GitHub”、“Azure DevOps Services”或“BitBucket” > “断开连接”。In the left menu, click Deployment Center > GitHub or Azure DevOps Services or BitBucket > Disconnect.

部署期间我的应用会发生什么情况?What happens to my app during deployment?

所有官方支持的部署方法都会更改应用的 /home/site/wwwroot 文件夹中的文件。All the officially supported deployment methods make changes to the files in the /home/site/wwwroot folder of your app. 这些文件与生产中运行的文件相同。These files are the same ones that are run in production. 因此,部署可能会因为文件锁定而失败。Therefore, the deployment can fail because of locked files. 生产中的应用在部署期间的行为也可能无法预测,因为不是所有文件都同时更新。The app in production may also behave unpredictably during deployment, because not all the files updated at the same time. 可通过多种不同方式避免这些问题:There are a few different ways to avoid these issues:

其他资源Additional Resources