You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Azure DevOps向Teams频道发送PR通知时触发400错误

解决Azure DevOps Service Hook对接Teams Incoming Webhook的400 Bad Request错误

以下是针对问题的排查和解决步骤:

  • 验证Webhook URL有效性
    确保从Teams复制的Incoming Webhook URL完整无缺,没有多余空格、换行或截断。标准URL格式应为https://outlook.office.com/webhook/[唯一ID]/IncomingWebhook/[密钥]/[频道ID]。可以直接用curl发送简单测试请求验证:

    curl -H "Content-Type: application/json" -d '{"text":"测试消息"}' "你的Webhook完整URL"
    

    如果这个请求失败,说明Webhook本身无效,需要重新在Teams频道创建Incoming Webhook。

  • 修正Service Hook的消息格式
    Azure DevOps默认的Service Hook消息格式可能不符合Teams Incoming Webhook的要求,导致400错误。需要自定义JSON模板:

    1. 打开Azure DevOps的Service Hook配置页面,切换到「消息」选项卡
    2. 选择「自定义JSON」,替换为Teams兼容的MessageCard格式,示例如下:
      {
        "@type": "MessageCard",
        "@context": "http://schema.org/extensions",
        "summary": "Pull Request 创建通知",
        "themeColor": "0078D7",
        "sections": [
          {
            "activityTitle": "**[${pullRequest.title}](${pullRequest.url})**",
            "activitySubtitle": "由 ${pullRequest.createdBy.displayName} 创建",
            "facts": [
              {
                "name": "源分支",
                "value": "${pullRequest.sourceRefName}"
              },
              {
                "name": "目标分支",
                "value": "${pullRequest.targetRefName}"
              }
            ],
            "markdown": true
          }
        ]
      }
      
    3. 保存配置后重新测试,确保所有变量(如${pullRequest.title})都是Azure DevOps Service Hook支持的内置变量。
  • 排查网络与权限限制

    • 确认Azure DevOps所在网络可以访问outlook.office.com域名,部分企业防火墙会拦截外部Webhook请求
    • 联系Teams管理员确认组织是否允许Incoming Webhook接收外部请求,部分组织会限制第三方服务调用Teams Webhook

内容的提问来源于stack exchange,提问作者Sanket Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 03:52:11