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 中的函式部署單位是函式應用程式。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:

 | - host.json
 | - MyFirstFunction
 | | - function.json
 | | - ...  
 | - MySecondFunction
 | | - function.json
 | | - ...  
 | - SharedCode
 | - bin

在2.x 版和更高版本的函式執行時間中,函數應用程式中的所有函式都必須共用相同的語言堆疊。In version 2.x and higher of the Functions runtime, all functions in the function app must share the same language stack.

主機. 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:


在取用方案上執行的 Linux 應用程式尚不支援持續部署。Continuous deployment is not yet supported for Linux apps running on a Consumption plan.

設定持續部署Set up continuous deployment

若要設定現有函數應用程式的持續部署,請完成下列步驟。To configure continuous deployment for an existing function app, complete these steps. 這些步驟會示範與 GitHub 存放庫的整合,但類似的步驟適用于 Azure Repos 或其他原始程式碼儲存機制。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 Pipelines (預覽) :當您需要更充分掌控組建時的最佳選擇。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.



設定持續整合之後,您就無法再于函式入口網站中編輯原始程式檔。After you configure continuous integration, you can no longer edit your source files in the Functions portal.

後續步驟Next steps