您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Azure Functions 的连续部署Continuous deployment for Azure Functions

可以使用 Azure Functions 通过连续部署代码源代码管理集成You can use Azure Functions to deploy your code continuously by using source control integration. 源代码管理集成可以实现代码更新触发 Azure 上部署的工作流。Source control integration enables a workflow in which a code update triggers deployment to Azure. 如果您是初次接触 Azure Functions,开始通过查看Azure Functions 概述If you're new to Azure Functions, get started by reviewing the Azure Functions overview.

持续部署是项目的一个不错的选择将多个集成和频繁的发布内容。Continuous deployment is a good option for projects where you integrate multiple and frequent contributions. 当使用连续部署时,您可以为你的代码,使团队可以轻松地进行协作维护单一事实来源。When you use continuous deployment, you maintain a single source of truth for your code, which allows teams to easily collaborate. 可以从以下源的代码位置的 Azure Functions 中配置持续部署:You can configure continuous deployment in Azure Functions from the following source code locations:

Functions 在 Azure 中单位是部署的 function app。The unit of deployment for functions in Azure is the function app. 在同一时间部署函数应用中的所有函数。All functions in a function app are deployed at the same time. 启用连续部署后,在 Azure 门户中的函数代码的访问权限配置为只读因为真相的来源设置为其他位置。After you enable continuous deployment, access to function code in the Azure portal is configured as read-only because the source of truth is set to be elsewhere.

连续部署的要求Requirements for continuous deployment

为连续部署成功,你的目录结构必须与 Azure Functions 需要的基本文件夹结构兼容。For continuous deployment to succeed, your directory structure must be compatible with the basic folder structure that Azure Functions expects.

特定函数应用中所有函数的代码均位于根项目文件夹中,其中包含主机配置文件和一个或多个子文件夹。The code for all the functions in a specific function app is located in a root project folder that contains a host configuration file and one or more subfolders. 每个子文件夹包含单独函数的代码。Each subfolder contains the code for a separate function. 文件夹结构所示的以下表示形式:The folder structure is shown in the following representation:

FunctionApp
 | - host.json
 | - Myfirstfunction
 | | - function.json
 | | - ...  
 | - mysecondfunction
 | | - function.json
 | | - ...  
 | - SharedCode
 | - bin

在版本 2.x 的 Functions 运行时,函数应用中的所有函数必须共享相同的语言堆栈。In version 2.x of the Functions runtime, all functions in the function app must share the same language stack.

Host.json文件包含特定于运行时的配置,则函数应用根文件夹中。The host.json file contains runtime-specific configurations and is in the root folder of the function app. 一个bin文件夹包含包和函数应用都需要其他库文件。A bin folder contains packages and other library files that the function app requires. 查看函数应用项目的语言特定要求:See the language-specific requirements for a function app project:

设置连续部署Set up continuous deployment

若要配置一个现有 function app 的连续部署,完成这些步骤。To configure continuous deployment for an existing function app, complete these steps. 步骤演示了与 GitHub 存储库的集成,但类似的步骤适用于 Azure 存储库或其他源代码存储库。The steps demonstrate integration with a GitHub repository, but similar steps apply for Azure Repos or other source code repositories.

  1. 在函数应用中Azure 门户,选择平台功能 > 部署中心In your function app in the Azure portal, select Platform features > Deployment Center.

    打开部署中心

  2. 在中部署中心,选择GitHub,然后选择AuthorizeIn Deployment Center, select GitHub, and then select Authorize. 如果您已经授权 GitHub,请选择继续If you've already authorized GitHub, select Continue.

    Azure 应用服务部署中心

  3. 在 GitHub 中,选择授权 AzureAppService按钮。In GitHub, select the Authorize AzureAppService button.

    授权 Azure 应用服务

    在中部署中心在 Azure 门户中,选择继续In Deployment Center in the Azure portal, select Continue.

  4. 选择以下生成提供程序之一:Select one of the following build providers:

    • 应用服务构建服务:当不需要在生成时,或者需要泛型生成最佳。App Service build service: Best when you don't need a build or if you need a generic build.
    • Azure 管道 (预览版) :你需要加强控制在生成时的最佳。Azure Pipelines (Preview): Best when you need more control over the build. 此提供程序目前处于预览状态。This provider currently is in preview.

    选择一个生成提供程序

  5. 配置特定于你指定的源控件选项的信息。Configure information specific to the source control option you specified. Github,必须输入或选择值组织存储库,并分支For GitHub, you must enter or select values for Organization, Repository, and Branch. 值基于代码的位置。The values are based on the location of your code. 然后选择“继续”。 Then, select Continue.

    配置 GitHub

  6. 查看所有详细信息,并选择完成完成你的部署配置。Review all details, and then select Finish to complete your deployment configuration.

    总结

完成该过程后,从指定的源的所有代码都部署到您的应用程序。When the process is finished, all code from the specified source is deployed to your app. 此时,部署源中的更改触发到 Azure 中的函数应用这些更改的部署。At that point, changes in the deployment source trigger a deployment of those changes to your function app in Azure.

部署方案Deployment scenarios

将现有函数移至连续部署Move existing functions to continuous deployment

如果您已经编写过函数Azure 门户并且你想要下载您的应用程序的内容,然后切换到连续部署,请转到概述函数应用的选项卡。If you've already written functions in the Azure portal and you want to download the contents of your app before you switch to continuous deployment, go to the Overview tab of your function app. 选择下载应用内容按钮。Select the Download app content button.

下载应用内容

备注

配置持续集成后,不再可以编辑在 Functions 门户中的源文件。After you configure continuous integration, you can no longer edit your source files in the Functions portal.

后续步骤Next steps