持續部署至 Azure App ServiceContinuous deployment to Azure App Service

Azure App Service可透過提取最新的更新, 從 GitHub、BitBucket 和Azure Repos存放庫進行持續部署。Azure App Service enables continuous deployment from GitHub, BitBucket, and Azure Repos repositories by pulling in the latest updates. 本文說明如何使用 Azure 入口網站, 透過 Kudu 組建服務或Azure Pipelines持續部署您的應用程式。This article shows you how to use the Azure portal to continuously deploy your app through the Kudu build service or Azure Pipelines.

如需原始檔控制服務的詳細資訊, 請參閱建立存放庫建立儲存機制 (GitHub)、建立存放庫建立儲存機制 (BitBucket)建立新的 Git 存放庫 (Azure Repos)For more information on the source control services, see Create a repo (GitHub), Create a repo (BitBucket), or Create a new Git repo (Azure Repos).

若要從入口網站不直接支援的雲端存放庫手動設定持續部署 (例如GitLab), 請參閱使用手動步驟設定連續部署To manually configure continuous deployment from a cloud repository that the portal doesn't directly support, such as GitLab, see Set up continuous deployment using manual steps.

準備您的存放庫Prepare your repository

若要從 Azure App Service 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.phpindex.php
Ruby (僅限 Linux)Ruby (Linux only) GemfileGemfile
Node.jsNode.js 含啟動指令碼的 server.jsapp.js, 或 package.jsonserver.js, app.js, or package.json with a start script
PythonPython *.pyrequirements.txtruntime.txt*.py, requirements.txt, or runtime.txt
HTMLHTML default.htmdefault.htmldefault.aspindex.htmindex.htmliisstart.htmdefault.htm, default.html, default.asp, index.htm, index.html, or iisstart.htm
WebJobsWebJobs <job_name > / u。<擴充功能 > 下方_應用程式_資料/工作/continuous_連續 webjobs,或_應用程式_資料/工作/triggered_觸發WebJobs。<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.

注意

如果您是在 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.

授權 Azure App ServiceAuthorize Azure App Service

若要使用 Azure Repos, 請確定您的 Azure DevOps 組織已連結至您的 Azure 訂用帳戶。To use Azure Repos, make sure your Azure DevOps organization is linked to your Azure subscription. 如需詳細資訊, 請參閱設定 Azure DevOps Services 帳戶, 使其可以部署至 web 應用程式For more information, see Set up an Azure DevOps Services account so it can deploy to a web app.

針對 Bitbucket 或 GitHub, 授權 Azure App Service 連接到您的存放庫。For Bitbucket or GitHub, authorize Azure App Service to connect to your repository. 您只需要對原始檔控制服務授權一次。You only need to authorize with a source control service once.

  1. Azure 入口網站左側導覽中選取 [應用程式服務], 然後選取您想要部署的 web 應用程式。Select App Services in the Azure portal left navigation, and then select the web app you want to deploy.

  2. 在 [應用程式] 頁面上, 選取左側功能表中的 [部署中心]。On the app page, select Deployment Center in the left menu.

  3. 在 [部署中心] 頁面上, 選取 [ GitHub ] 或 [ Bitbucket], 然後選取 [授權]。On the Deployment Center page, select GitHub or Bitbucket, and then select Authorize.

    選取 [原始檔控制服務], 然後選取 [授權]。

  4. 視需要登入服務, 並遵循授權提示。Sign in to the service if necessary, and follow the authorization prompts.

啟用持續部署Enable continuous deployment

在您授權原始檔控制服務之後, 請透過內建的Kudu App Service 組建伺服器, 或透過Azure Pipelines, 設定您的應用程式以進行持續部署。After you authorize a source control service, configure your app for continuous deployment through the built-in Kudu App Service build server, or through Azure Pipelines.

選項 1:使用 App Service 組建服務Option 1: Use the App Service build service

您可以使用內建的 Kudu App Service 組建伺服器, 從 GitHub、Bitbucket 或 Azure Repos 持續部署。You can use the built-in Kudu App Service build server to continuously deploy from GitHub, Bitbucket, or Azure Repos.

  1. Azure 入口網站左側導覽中選取 [應用程式服務], 然後選取您想要部署的 web 應用程式。Select App Services in the Azure portal left navigation, and then select the web app you want to deploy.

  2. 在 [應用程式] 頁面上, 選取左側功能表中的 [部署中心]。On the app page, select Deployment Center in the left menu.

  3. 在 [部署中心] 頁面上選取您的授權原始檔控制提供者, 然後選取 [繼續]。Select your authorized source control provider on the Deployment Center page, and select Continue. 針對 GitHub 或 Bitbucket, 您也可以選取 [變更帳戶] 來變更授權的帳戶。For GitHub or Bitbucket, you can also select Change account to change the authorized account.

    注意

    若要使用 Azure Repos, 請確定您的 Azure DevOps Services 組織已連結至您的 Azure 訂用帳戶。To use Azure Repos, make sure your Azure DevOps Services organization is linked to your Azure subscription. 如需詳細資訊, 請參閱設定 Azure DevOps Services 帳戶, 使其可以部署至 web 應用程式For more information, see Set up an Azure DevOps Services account so it can deploy to a web app.

  4. 若是 GitHub 或 Azure Repos, 請在 [組建提供者] 頁面上, 選取 [ App Service 組建服務], 然後選取 [繼續]。For GitHub or Azure Repos, on the Build provider page, select App Service build service, and then select Continue. Bitbucket 一律會使用 App Service 組建服務。Bitbucket always uses the App Service build service.

    選取 [App Service 組建服務], 然後選取 [繼續]。

  5. 在 [設定] 頁面上:On the Configure page:

    • 針對 [GitHub], 下拉並選取您想要持續部署的組織、存放分支For GitHub, drop down and select the Organization, Repository, and Branch you want to deploy continuously.

      注意

      如果您沒有看到任何存放庫, 您可能需要在 GitHub 中授權 Azure App Service。If you don't see any repositories, you may need to authorize Azure App Service in GitHub. 流覽至您的 GitHub 存放庫, 並移至 設定 > 應用程式 > 授權 OAuth 應用Browse to your GitHub repository and go to Settings > Applications > Authorized OAuth Apps. 選取 [ Azure App Service], 然後選取 [授與]。Select Azure App Service, and then select Grant.

    • 針對 [Bitbucket], 選取您想要持續部署的 Bitbucket小組、存放分支For Bitbucket, select the Bitbucket Team, Repository, and Branch you want to deploy continuously.

    • 針對 Azure Repos, 請選取您想要持續部署的Azure DevOps 組織專案、存放分支For Azure Repos, select the Azure DevOps Organization, Project, Repository, and Branch you want to deploy continuously.

      注意

      如果您的 Azure DevOps 組織未列出, 請確定它已連結至您的 Azure 訂用帳戶。If your Azure DevOps organization isn't listed, make sure it's linked to your Azure subscription. 如需詳細資訊, 請參閱設定 Azure DevOps Services 帳戶, 使其可以部署至 web 應用程式For more information, see Set up an Azure DevOps Services account so it can deploy to a web app..

  6. 選取 繼續Select Continue.

    填入存放庫資訊, 然後選取 [繼續]。

  7. 設定組建提供者之後, 請檢查 [摘要] 頁面上的設定, 然後選取 [完成]After you configure the build provider, review the settings on the Summary page, and then select Finish.

    所選存放庫和分支中的新認可現在會持續部署到您的 App Service 應用程式中。New commits in the selected repository and branch now deploy continuously into your App Service app. 您可以在 [部署中心] 頁面上追蹤認可和部署。You can track the commits and deployments on the Deployment Center page.

    在部署中心追蹤認可和部署

選項 2:使用 Azure PipelinesOption 2: Use Azure Pipelines

如果您的帳戶具有必要的許可權, 您可以設定 Azure Pipelines 從 GitHub 或 Azure Repos 存放庫持續部署。If your account has the necessary permissions, you can set up Azure Pipelines to continuously deploy from GitHub or Azure Repos repositories. 如需透過 Azure Pipelines 部署的詳細資訊, 請參閱將 web 應用程式部署至 Azure App 服務For more information about deploying through Azure Pipelines, see Deploy a web app to Azure App Services.

若要 Azure App Service 在 Azure DevOps 組織中建立持續傳遞 Azure Pipelines:For Azure App Service to create continuous delivery Azure Pipelines in your Azure DevOps organization:

  • 您的 Azure 帳戶必須具有寫入 Azure Active Directory 和建立服務的許可權。Your Azure account must have permissions to write to Azure Active Directory and create a service.

  • 您的 Azure 帳戶必須具有 Azure 訂用帳戶中的擁有者角色。Your Azure account must have the Owner role in your Azure subscription.

  • 您必須是您想要使用之 Azure DevOps 專案中的系統管理員。You must be an administrator in the Azure DevOps project you want to use.

若要設定 Azure Pipelines (預覽):To configure Azure Pipelines (Preview):

  1. Azure 入口網站左側導覽中選取 [應用程式服務], 然後選取您想要部署的 web 應用程式。Select App Services in the Azure portal left navigation, and then select the web app you want to deploy.

  2. 在 [應用程式] 頁面上, 選取左側功能表中的 [部署中心]。On the app page, select Deployment Center in the left menu.

  3. 在 [組建提供者] 頁面上, 選取 [ Azure Pipelines (預覽) ], 然後選取 [繼續]。On the Build provider page, select Azure Pipelines (Preview), and then select Continue.

  4. 在 [設定] 頁面的 [程式代碼] 區段中:On the Configure page, in the Code section:

    • 針對 [GitHub], 下拉並選取您想要持續部署的組織、存放分支For GitHub, drop down and select the Organization, Repository, and Branch you want to deploy continuously.

      注意

      如果您沒有看到任何存放庫, 您可能需要在 GitHub 中授權 Azure App Service。If you don't see any repositories, you may need to authorize Azure App Service in GitHub. 流覽至您的 GitHub 存放庫, 並移至 設定 > 應用程式 > 授權 OAuth 應用Browse to your GitHub repository and go to Settings > Applications > Authorized OAuth Apps. 選取 [ Azure App Service], 然後選取 [授與]。Select Azure App Service, and then select Grant.

    • 針對 Azure Repos, 請選取您想要持續部署的Azure DevOps 組織專案、存放分支, 或設定新的 Azure DevOps 組織。For Azure Repos, select the Azure DevOps Organization, Project, Repository, and Branch you want to deploy continuously, or configure a new Azure DevOps organization.

      注意

      如果您現有的 Azure DevOps 組織未列出, 您可能需要將它連結到您的 Azure 訂用帳戶。If your existing Azure DevOps organization isn't listed, you may need to link it to your Azure subscription. 如需詳細資訊, 請參閱定義您的 CD 發行管線For more information, see Define your CD release pipeline.

  5. 選取 繼續Select Continue.

  6. 針對 Azure Repos, 請在 [組建] 區段中, 指定 Azure Pipelines 應該用來執行組建工作的語言架構, 然後選取 [繼續]。For Azure Repos, in the Build section, specify the language framework that Azure Pipelines should use to run build tasks, and then select Continue.

  7. 在 [測試] 頁面上, 選擇是否要啟用負載測試, 然後選取 [繼續]。On the Test page, choose whether to enable load tests, and then select Continue.

  8. 視您的 App Service 方案定價層而定, 您可能會看到 [部署至預備環境] 頁面。Depending on your App Service plan pricing tier, you may see a Deploy to staging page. 選擇是否要啟用部署位置, 然後選取 [繼續]。Choose whether to enable deployment slots, and then select Continue.

    注意

    Azure Pipelines 不允許持續傳遞至生產位置。Azure Pipelines doesn't allow continuous delivery to the production slot. 這種限制可防止意外部署到生產環境。This restriction prevents accidental deployments to production. 設定持續傳遞至預備位置、驗證其中的變更, 然後在您準備就緒時交換位置。Set up continuous delivery to a staging slot, verify the changes there, and then swap the slots when you are ready.

  9. 設定組建提供者之後, 請檢查 [摘要] 頁面上的設定, 然後選取 [完成]After you configure the build provider, review the settings on the Summary page, and then select Finish.

    所選存放庫和分支中的新認可現在會持續部署到您的 App Service 應用程式中。New commits in the selected repository and branch now deploy continuously into your App Service app. 您可以在 [部署中心] 頁面上追蹤認可和部署。You can track the commits and deployments on the Deployment Center page.

    在部署中心追蹤認可和部署

停用連續部署Disable continuous deployment

若要停用持續部署, 請在應用程式的 [部署中心] 頁面頂端選取 [中斷連線]To disable continuous deployment, select Disconnect at the top of your app's Deployment Center page.

停用連續部署

在部署期間我的應用程式會發生什麼事?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