設定 Teams 連接器
Teams 團隊 啟用 Webhook 連接器

設定名稱、圖片

建立完後 會取得 webhook 的 URL

紅框 為webhook名稱、橘框 為 剛剛設定的圖片

先用 Postman 測試 API 是否正常


微軟 官方文件 - Post an actionable message card to an Office 365 group
Azure Devops pipeline 設定 Webhook 通知 Teams
- 設定 pipeline
在pipeline 流程中加入PowerShell 用以呼叫 Webhook API 
- task: PowerShell@2
  displayName: Teams Webhook
  inputs:
    targetType: 'inline'
    script: |
      # Write your PowerShell commands here.
      $url = "$(WebhookURL)";
      $headers = @{ 'Content-Type' = 'application/json'; }
      $body = (@{
                  '@context' = "https://schema.org/extensions"
                  '@type'= "MessageCard"
                  'themeColor'= "0072C6"
                  'title'= "Push To Octopus Notification $(Build.BuildNumber)-$(prefix)"
                  'text'= "Click **Learn More** to learn more about Actionable Messages!"
                  'potentialAction'= @(
                  @{
                      "@type"= "OpenUri"
                      "name"= "Check Octopus"
                      'targets'= @(
                                      @{ 
                                          "os"= "default" 
                                          "uri"= "https://docs.microsoft.com/outlook/actionable-messages" 
                                      }
                                  )
                      
                  }
                )
              } | ConvertTo-Json -Depth 4)
      Invoke-RestMethod $url -Method 'POST' -Headers $headers -Body $body
- 確認結果

 
轉載請註明來源,若有任何錯誤或表達不清楚的地方,歡迎在下方評論區留言,也可以來信至 leozheng0621@gmail.com
如果文章對您有幫助,歡迎斗內(donate),請我喝杯咖啡