Try   HackMD

Hands-on: Logic App CI/CD with Azure DevOps

tags: Workshop Logic App Azure DevOps 2022

Logic App Resouece Structure

  • 目前 Logic App 支援兩種 Tier,分別為 Standard (Single-tenant) 及 Consumption (Multi-tenant)
  • 在 multi-tenant 模型中,Logic App 資源結構只能包含一個工作流。由於這種一對一的關係,Logic App 和 Workflow 通常被視為同義詞並引用。
  • 而在 single-tenant 模型中,Logic App 資源結構可包含多個工作流。這種一對多的關係意味著在同一個 Logic App 中,工作流可以共享和重用其他資源。在 single-tenant 的模式下,也可使用到更多的功能,如獨立的 compute resource 及網路環境等

課程實作大綱

0) 建置 Azure DevOps Organization

建立新組織

  • Azure DevOps 頁面,選擇 開始免費使用
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 選擇 Taiwan
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 填寫你的組織名稱、地區(建議可以選擇 Central US)
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 點選 Continuous,開始進行服務的建立
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 完成後,會跳轉至以下畫面,建立第一個專案,選擇 Private
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

第一個專案

  • 建立完成後會看到一個開好的專案
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 點選左上角的
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    回到組織首頁

Billing 設定

:bulb: 因目前免費的一條 pipeline 須提前申請,因此需綁定 billing 才可使用 pipeline,免費 pipeline 申請方式請參考 Reference

  • 在首頁中,點選左下方的 Organization Setting
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 點選 Billing,選擇 Set up billing,選擇你可使用的訂閱 (免費試用/MSDN 訂閱不可使用)
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 將 MS Hosted CI/CD 數量調整為 1
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

建置今日 Project 所使用之專案

  • 回到首頁,點選右上角
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 填寫 Project name logic-app-workshop,Visibility 選擇 Private,完成後 Create
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

1) Initial Logic App Enviornment

Region 可設定於 Japan East / East Asia,此章節會建立 2* Consumption Logic App 及 2* Standard Logic App,分別為 dev 及 prod 環境所使用

  • Azure Portal 上,建立 Logic App 的資源
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 設定 Logic App 參數,建立一個全新的 resource group 為今日 lab 所使用,並選擇 Consumption 的 plan type,設定完成後點選 Review + Create
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 確認資料正確後點選 Create
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 部屬完成後點選 Go to resource
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 點選後會直接跳轉至 Logic App Designer,選擇 When a HTTP request is received
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • trigger 建立完成後,點選 Save,後續會透過程式碼式的方式添加 Action
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 再新增一個 Consumption plan type 的 production Logic App
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 新增一個 plan type 為 Standard 的 Dev Logic App
    • 選擇 Standard
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
    • Windows Plan 選擇 Create New
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
    • Sku and size 選擇 WS1
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
    • Stroage 選擇 Create New (storage命名僅可字母+數字)
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
    • Application Insight 選擇 Create New
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
    • Review 確認沒問題後點選 Create
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
  • 再新增一個 Prod 的 Standard Logic App (步驟同 Dev)
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

2) Consumption Tier Logic App (Multi-tenant) 的開發

使用 Visual Studio Code

  • 安裝 Azure Logic App (Consumption) Extension

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 到桌面,建立新的資料夾,命名為consumption (或任意命名)

  • 開啟 Visual Studio Code,選擇 Open Folder,選到剛剛建立的新資料夾

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 選擇左邊菜單,點選

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    ,找到 Azure Logic App (CONSUMPTION) 的 Extension,點選 Sign in to Azure
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 輸入帳號

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 登入完成後,顯示以下畫面

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 回到 Visual Studio Code,會出現此帳號可用之訂閱,如果訂閱太多,可以用 filter

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 在先前建立 Logic App 的訂閱下找到 Dev Logic App 資源,選擇 Dev Logic App > 右鍵 > Open in Designer,可查看目前 Azure 上 Logic App 設定的流程

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • Logic App > 右鍵 > Open in Editor,可透過編輯 json 修改流程

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 添加 HTTPResponse 兩個 action,在 "actions": {} 區塊內將以下程式碼加入

    ​​​​"HTTP": { ​​​​ "runAfter": {}, ​​​​ "type": "Http", ​​​​ "inputs": { ​​​​ "method": "GET", ​​​​ "uri": "https://cat-fact.herokuapp.com/facts/" ​​​​ } ​​​​}, ​​​​"Response": { ​​​​ "runAfter": { ​​​​ "HTTP": [ ​​​​ "Succeeded" ​​​​ ] ​​​​ }, ​​​​ "type": "Response", ​​​​ "kind": "Http", ​​​​ "inputs": { ​​​​ "statusCode": "@outputs('HTTP')['statusCode']", ​​​​ "headers": { ​​​​ "devops_test": "0602" ​​​​ }, ​​​​ "body": "@body('HTTP')" ​​​​ } ​​​​}

  • 儲存後會直接 update Logic App

  • Output 顯示 Updated 後,點選 Dev Logic App 的

    圖示可直接開啟 Designer,確認 actions 經更新

  • 透過 Dev Logic App > Versions 可查看過去編輯版本

  • 測試 API

    • 回到 Azure Portal ,找到測試用的 Dev Logic App 環境,點選 Logic app desgigner > When a HTTP request is received,取得 HTTP POST URL

    • 使用 POSTMAN,選擇 POST,並將 HTTP POST URL 填入

    • 使用 curl

      ​​​​​​​​curl -d "Content-Length:0" -X POST "<Logic_App_HTTP_POST URL>"
      

調整 ARM template 參數

  • 如果怕改錯,可直接使用 sample code for logic app huier23/logic-app-consumption
  • 將 logic app 部屬檔添加至 project 中,點選左邊菜單的
    ,選擇 Dev Logic App > Add to Project
  • 點選左邊菜單的
    ,會出現兩個檔案,分別為 xxxxx.definition.json 和 xxxxx.parameters.json
  • xxxxxxx.definition.json 修改檔名為 logicapp.definition.json
    • parameters 區域之內容取代為以下
    ​​​​"workflows_logicapp_name": { ​​​​ "defaultValue": "<dev-logic-app-name>", ​​​​ "type": "string" ​​​​}, ​​​​"workflows_logicapp_location": { ​​​​ "defaultValue": "<logic-app-location>", ​​​​ "type": "string" ​​​​}, ​​​​"workflows_http_URL": { ​​​​ "defaultValue": "", ​​​​ "type": "string" ​​​​}
    • resources 內的 locationname 修改引用參數之名稱
    ​​​​"location": "[parameters('workflows_logicapp_location')]", ​​​​"name": "[parameters('workflows_logicapp_name')]",
    • resources 內的 actions > HTTP 區域取代為
    ​​​​"HTTP": { ​​​​ "runAfter": {}, ​​​​ "type": "Http", ​​​​ "inputs": { ​​​​ "method": "GET", ​​​​ "uri": "[parameters('workflows_http_URL')]" ​​​​ } ​​​​},
  • xxxxxxx.parameters.json 修改檔名為 logicapp.parameters.json
    • 調整 parameters 區域內的內容取代為以下
    ​​​​"workflows_logicapp_name": { ​​​​ "value": "<dev-logic-app-name>" ​​​​}, ​​​​"workflows_logicapp_location": { ​​​​ "value": "<logic-app-location>" ​​​​}, ​​​​"workflows_http_URL": { ​​​​ "value": "https://cat-fact.herokuapp.com/facts/" ​​​​}
  • 完成後儲存

設定 CI/CD on Azure DevOps

  • Azure DevOps,點選 Repos,新增一個 Repo
  • 設定 Repository Name,完成後點選 Create
  • 複製 URL 網址
  • 回到 Visual Studio Code,開啟 terminal

  • 如果習慣用 cmd,terminal 右上的 + 可以新增 Command Prompt

  • 將程式碼推送至遠端 repository

    • 使用 git 將程式碼推送至遠端程式庫
      ​​​​​​​​git init .
      ​​​​​​​​git add .
      ​​​​​​​​git commit -m "first commit"
      ​​​​​​​​git remote add origin <remote-repo-url>
      ​​​​​​​​git push origin master
      
    • 登入

    :bulb: 如需使用 PAT 做驗證, 為 Azure DevOps 之 PAT token

    • 點選 Azure DevOps 畫面右上人頭, … > User Settings
    • 選擇 Personal Access Token
    • New Token,並給予 Code Full access 的權限,完成後將 PAT 記下
    • 在 terminal 中填入 PAT
  • 回到 Azure DevOps,確認檔案已上傳

  • 選擇 Pepeline > Release > Create Pipeline

  • 點選 Empty Job

  • 將 Stage 命名為 Prod,完成後點選 X

  • 點選 Add an artifact

  • 設定 Artifacts,完成後點選 Add

    • Source type: Azure Repo
    • project: 目前的 porject
    • Source (repository): 選擇存放 consumption logic app json 檔案的 repository
    • Default branch: master
  • 設定 continuous deployment,點選 Artifact 右上方的

    ,並將 Continuous deployment trigger 切換至 Enabled

  • 修改 satge 的 job,點選 Prod stage 的 1 job, 0 task

  • 在 Agent job 區塊,點選 +,搜尋 arm,將 ARM template deployment 添加至 job 中

  • 點選 ARM Template deployment: Resource Group scope 的 task 進行設定

    • Deployment scope: Resource Group
    • Azure Resource Manager connection: xxx's subscription
    • Subscription: xxx's subscription
    • Action: Create or update resource group
    • Resource group: $(RESOURCE_GROUP)
    • Location: $(LOCATION)
    • Template location: Linked artifact
    • Template: $(System.DefaultWorkingDirectory)/**/**.definition.json
    • Override template parameters: -workflows_logicapp_name "$(LOGIC_APP)" -workflows_http_URL "$(REQUEST_URL)"
    • Deployment mode: Incremental


  • 設定 pipeline variable,Variables > Variable groups > Manage variable groups

  • 點選

    新增一組 variable group

  • 修改 Variable group name,並將 RESOURCE_GROUPLOCATION 添加至 Variables 的 key,並分別填上正確的 value,完成後點選 Save

  • 回到 release pipeline > variables > variable groups > link variable group,點選剛剛建立的 variable group,完成後點選 link

  • 回到 Pipeline 設定 pepeline variables,新增兩組 key-value

    • LOGIC_APP = Prod Logic App 名稱
    • REQUEST_URL = https://cat-fact.herokuapp.com/facts/
  • 回到 Pipeline 設定 Per-deployment conditions,點選 Prod stage 的

    ,將 Pre-deployment approvals 改為 Enabled

  • 修改 release pipeline 的名稱 Release to Logic App (Consumption)

  • 點選 Save > Create release,此時可以查看 Relese-1 的執行狀況

  • 同意部屬至 Prod Stage

  • 回到 Azure Portal 上,查看 Prod Logic App,確認已有更新,並透過 postman 確認

3) Standard Tier Logic App (Single-tenant)

About


When you create logic apps using the Logic App (Standard) resource type, your workflows are powered by the redesigned single-tenant Azure Logic Apps runtime. This runtime uses the Azure Functions extensibility model extensibility and is hosted as an extension on the Azure Functions runtime.

By using standard build and deploy options, you can focus on app development separately from infrastructure deployment.

  • You can locally run and test logic app workflows in the Visual Studio Code development environment.
  • Your logic app can include multiple stateful and stateless workflows.
  • Workflows in the same logic app and tenant run in the same process as the Azure Logic Apps runtime, so they share the same resources and provide better performance.

Logic app project structure

Prerequisites

使用 Visual Studio Code

  • 建立新的資料夾,命名為CatFactProj
  • 開啟 Visual Studio Code,選擇 Open Folder
  • 開啟剛剛建立的新資料夾
  • 左邊菜單點選
    > Azure Logic App (Standard) 的 Extension,點選 Sign in to Azure (如先前已有登入此處無須再登)
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 登入完成後,點選 Logic Apps (STANDARD) 的
    新增一個 Logic App Project
  • 選擇 Stateful Workflow
  • 填入 workflow 的名稱 catfact-api (可任意命名)
  • 點選左邊菜單的 Explorer (第一個),找到在 catfact-api 資料夾底下的 workflow.json > 右鍵 > Open in Designer

    :bulb: 第一次開啟 Designer 會需要時間

  • 選擇 Use Connectors from Azure
  • 選擇先前建立 Logic App 資源的資源群組
  • Designer 開啟完成後,選擇 trigger 為 When a HTTP request is received
  • 點選 + > Add an action 來新增下一動
  • 在 Add an action 區塊中搜尋 http,選擇
    的 action,並設定參數
    • Method: GET
    • URI: https://cat-fact.herokuapp.com/facts/
  • 點選 + > Add an action 來新增下一動
  • 在 Add an action 區塊中搜尋 response,選擇
    的 action,並設定參數
    • Status Code:

    • Body:

  • 完成後點選 Save
  • 確認 workflow.json 有更新

(無環境不操作) Local 測試

  • Azure Portal,找到 Logic App 建立時一併建立的 Azure Storage Account (使用 Dev Logic App 的 Storage)
  • 點選 Storage 進入後,找到 Access Keys > Show Keys,將 Connection String 記下 (使用 key1 或 key2 都可以)
  • 回到 Visual Studio Code,找到 local.settings.json 的檔案,開啟編輯,將原本的 "AzureWebJobsStorage": "UseDevelopmentStorage=true", 取代成 "AzureWebJobsStorage": "<storage-access-key>",後,儲存
  • 在 .vscode 資料夾底下,編輯 launch.json 檔案,將內容全部取代成以下
    ​​​​{ ​​​​ "version": "0.2.0", ​​​​ "configurations": [ ​​​​ { ​​​​ "name": "Attach to .NET Functions", ​​​​ "type": "coreclr", ​​​​ "request": "attach", ​​​​ "processId": "${command:azureLogicAppsStandard.pickProcess}" ​​​​ } ​​​​ ] ​​​​}
  • 點選左邊菜單,
    Run and debug >

  • 開始執行後出現以下畫面
  • 回到
    Explorer,選擇 catfact-api 資料夾下的 workflow.json,右鍵選擇 Overview
  • 將 Callback URL 複製下來
  • 到 Postman 上,使用 POST 測試
  • 回到 Visual Studio Code > Overview 上,可察看執行紀錄,點選 show run
  • 查看每一動的執行時間及結果
  • 點選上放的
    ,進行 disconnect
  • 手動部屬到 Azure Logic App (Standard)
    • 在 Explorer 空白處點選右建 > Deploy to Logic App
    • 選擇 Logic App (Standard) in Azure 為測試用的 Logic App 資源
    • 如有警示窗告知會進行覆蓋,選擇 Deploy
    • 右下的通知點選 Output window 可查看部屬狀況
    • 部屬完成
  • Azure Portal Dev Logic App 環境確認 workflow 已部屬完成
  • 透過
    > Run 驗證,

(無環境操作) 使用 sample code

:bulb: 若本機尚未安裝環境或安裝有狀況,可先使用 sample 進行後續課程

  • 下載 huier23/logic-app-standard
    ​​​​git clone https://github.com/huier23/logic-app-standard.git
    
  • 將 logic-app-standard 開啟,把 pet-food-facts-api 剪下貼到桌面
  • 用 Visual Studio Code 將 logic-app-standard 開啟
  • 編輯 local.settings.json 檔案,修改以下內容為個人資訊後儲存
    • "WORKFLOWS_TENANT_ID": "tenant-id",
    • "WORKFLOWS_SUBSCRIPTION_ID": "subscription-id",
    • "WORKFLOWS_RESOURCE_GROUP_NAME": "rg-name",
    • "WORKFLOWS_LOCATION_NAME": "location-with-no-space",
    • tenant-id 取得:Azure Active Directory 中可取得 Tenant ID
    • subsctiption-id 取得:resource group 中的 overview
  • 開啟終端機,輸入指令git remote remove origin

設定 CI/CD on Azure DevOps

  • Azure DevOps,選擇 Repos,建立新的 Repository

  • 將新的 Repository 命名為 logic-app-standard (或任意命名)

  • 複製 git repository url

  • 回到 Visual Studio Code 上,上方選單 Terminal > New Terminal,開啟終端機

  • 可改成使用 cmd

  • 使用 git 將程式碼推送至遠端程式庫

    ​​​​git init .
    ​​​​git add .
    ​​​​git commit -m "first commit"
    ​​​​git remote add origin <remote-repo-url>
    ​​​​git push origin master
    

  • 確認程式碼已有推送成功

  • 點選左方菜單 > Pipelines > Create Pipeline

  • 選擇 Use the classic editor

  • 選擇 standard 的 repo

  • 使用空白的 template,選擇 Empty Job

  • 點選 Agent Job 1 的 ,搜尋 copy,將 Copy files > Add

  • 設定 Copy files

    • Source Folder: (留白)
    • Contens: **
    • Target Folder: $(Build.ArtifactStagingDirectory)/$(Build.BuildId)
  • 再新增一個,搜尋 Archive,將 Archive files > Add

  • 設定 Archive files

    • Root folder or file to archive: $(Build.ArtifactStagingDirectory)/$(Build.BuildId)
    • Prepend root folder name to archive paths: 不勾選
    • Archive type: zip
    • Archive file to create: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
  • 新增第三個,搜尋 Publish,將 Publish build artifacts > Add

  • 設定 Publish Artifact

    • Path to publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
  • 修改 Pipeline 名稱為 logic-app-standard-CI (或任意命名)

  • 設定 Continuous Integration,點選上方 Trigger > Enable continuous integration

  • 完成後點選 Save & queue > Save and run

  • 建立 Release Piplien,點選 Release >

    >

  • 選擇 Empty job

  • Stage 命名為 Prod (或任意命名)

  • 新增部屬來源,點選 + Add an artifact,並新增來源為 build pipeline

    • Source Type: Build
    • Source (build pipeline): Logic App standard CI
    • Default version: Latest
  • 設定 Continuous deployment,點選 artifact 的

    ,將 Continuous deployment trigger 做 Enable

  • 設定 Prod 的 task,點選 1job, 0 task

  • 點選 Agent job 的 + > 搜尋 function > Azure Functions > Add

  • 設定 Azure Function App Deploy 的 task

    • Azure subscription: xxxx's subscription
    • App type: Function App on Windows
    • App name: $(LOGIC_APP)
    • Package or folder: $(System.DefaultWorkingDirectory)/**/drop/*.zip
    • Additional Deployment Options | Deployment method: Zip Deploy
  • 設定 Pipeline variable,點選 上方 Variables > + Add,將 LOGIC_APP 及 value 設定 (value 為要部屬的 logic app resource name)

  • 完成後點選 Pepeline,點選 Prod stage 的

    ,將 Pre-deployment approvals 設定為 Enabled,並加入審核人

  • 修改 release pipeline 名稱後 Save

  • 點選右上方的 Create Relase > Create ,開始執行 release-1

  • 點擊狀態列出現的 Release-1,可查看此次 release 狀況

  • 因 Prod 有設定審核機制,點選 Approve,允許部屬

  • 點選 Logs 可查看 raw log

(無環境不操作) 新增新 workflow

  • 回到 Visual Studio Code,選擇左方菜單的
  • 點選
    Create new project
  • 選擇同樣的 CatFactProj
  • 選擇 Stateless
  • 將API命名為 pet-food-facts-api (或任意命名)
  • host.json、local.settings.json、.gitignore.json、.funcignore.json 皆不覆蓋,選擇 NO



    :bulb: 確認 local.settings.json 檔案中的 AzureWebJobsStorage 設定是否為 Azure Blob Storage

  • 選擇 pet-food-facts-api 資料夾下的 workflow.json,右鍵 > Open in Designer
  • 新增 When a HTTP request is received 的 trigger,及 HTTP 的 action,HTTP 同樣使用 GET,URI 設定為 https://world.openpetfoodfacts.org/api/v0/product/20106836.json
  • 添加 Response 並設定,完成後點選 Save
  • 測試
  • 從 Overview 中確認 Callback URL
  • 使用本機 postman 驗證
  • 部屬


  • 驗證 Azure 中的測試環境中有多一個 workflow

(無環境操作) 新增新 workflow

  • 將原本移動到桌面的 pet-food-facts-api 移動回 logic-app=standard 的資料夾下

Checkin 程式碼並驗證自動化流程

  • 回到 Visual Studio Code,開啟 terminal,執行 git 做推送
    ​​​​git add .
    ​​​​git commit -m "add pet-food-facts-api workflow"
    ​​​​git push origin master
    
  • 回到 Azure DevOps,確認 build pipeline 有自動執行
  • 到 Release 確認工作有執行
  • 點選
    做 approve 允許部屬至 Prod
  • 確認有成功部屬
  • 到 prod-logic-app 上確認新的 workflow

資源移除

  • Remove Azure DevOps Organization: Organization Setting > Delete
  • Remove Azure DevOps Project: Project Setting > Delete
  • Azure Resource Reomove

Reference