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

能否用Terraform创建Azure DevOps通知及关联团队配置?

答案

可以通过Terraform完成所有需求

你之前查看的agent_pool资源仅用于管理Azure DevOps代理池,和团队创建、通知订阅完全无关,所以找不到对应内容。你需要使用Provider中专门的资源来实现需求,具体如下:

1. 创建Azure DevOps团队

使用azuredevops_team资源,需先关联对应项目:

resource "azuredevops_project" "demo_project" {
  name               = "DemoProject"
  description        = "用于测试通知的演示项目"
  visibility         = "private"
  version_control    = "Git"
  work_item_template = "Agile"
}

resource "azuredevops_team" "notify_team" {
  project_id  = azuredevops_project.demo_project.id
  name        = "NotifyTeam"
  description = "接收流水线通知的专属团队"
}

2. 配置特定通知订阅并指定团队为接收方

使用azuredevops_notification_subscription资源,可针对不同事件创建订阅,以下是你需求中的两个场景示例:

场景1:流水线失败时通知团队

resource "azuredevops_notification_subscription" "pipeline_failure_alert" {
  project_id = azuredevops_project.demo_project.id
  name       = "流水线失败告警"
  event_type = "ms.vss-build.build-completed-event"

  filter {
    criteria = <<EOF
    <Filter xmlns="http://schemas.microsoft.com/VisualStudio/2010/NotificationFilter">
      <Expression>
        <And>
          <Expression>
            <FieldOperation Field="Build.Status" Operator="Equals">Failed</FieldOperation>
          </Expression>
        </And>
      </Expression>
    </Filter>
EOF
  }

  subscriber {
    type       = "team"
    identifier = azuredevops_team.notify_team.id
  }

  delivery {
    type = "email"
  }
}

场景2:运行阶段待审批时提醒团队

resource "azuredevops_notification_subscription" "approval_pending_alert" {
  project_id = azuredevops_project.demo_project.id
  name       = "待审批提醒"
  event_type = "ms.vss-release.release-deployment-pending-approvals-event"

  filter {
    criteria = <<EOF
    <Filter xmlns="http://schemas.microsoft.com/VisualStudio/2010/NotificationFilter">
      <Expression>
        <And>
          <Expression>
            <FieldOperation Field="Deployment.Approval.Status" Operator="Equals">Pending</FieldOperation>
          </Expression>
        </And>
      </Expression>
    </Filter>
EOF
  }

  subscriber {
    type       = "team"
    identifier = azuredevops_team.notify_team.id
  }

  delivery {
    type = "email"
  }
}

关键说明

  • event_type需匹配Azure DevOps官方定义的事件类型,可通过平台通知中心的“新建订阅”界面查看对应标识
  • 过滤规则(filter中的XML)可根据需求调整,比如指定特定流水线、阶段等
  • 将subscriber的type设为team并传入团队ID,即可把该团队设置为邮件接收方

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 03:27:53