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:

在 Azure functions 單位是部署的函式應用程式。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 函式必須要有基本的資料夾結構相容。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:

 | - 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. A 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

若要設定持續部署現有的函式應用程式,完成這些步驟。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,然後選取授權In Deployment Center, select GitHub, and then select Authorize. 如果您已經已獲授權 GitHub,請選取繼續If you've already authorized GitHub, select Continue.

    Azure App Service 部署中心

  3. 在 GitHub 中,選取授權 AzureAppService 按鈕。In GitHub, select the Authorize AzureAppService button.

    授權 Azure App Service

    部署中心在 Azure 入口網站中,選取繼續In Deployment Center in the Azure portal, select Continue.

  4. 選取其中一個下列的組建提供者:Select one of the following build providers:

    • App Service 建置服務:當您不需要建置,或如果您需要泛型組建的最佳。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