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

如何通过Terraform为Azure DevOps非默认分支配置分支策略

配置Azure DevOps非默认分支的分支策略

要将azuredevops_branch_policy_status_check策略应用到指定的非默认分支(比如test-branch),你需要修改资源中的settings.scope块,具体调整如下:

  1. 移除默认分支绑定配置:删除原代码中match_type = "DefaultBranch"的scope块,不再将策略关联到默认分支。
  2. 指定目标非默认分支:在保留的scope块中,将repository_ref的值替换为目标分支的完整引用路径refs/heads/test-branch,保持match_type = "Exact"以精确匹配该分支。

修改后的完整Terraform代码示例:

resource "azuredevops_user_entitlement" "example-entitlement" {
  principal_name       = var.username
  account_license_type = "basic"
}

resource "azuredevops_branch_policy_status_check" "example-status-check" {
  project_id = azuredevops_project.project.id

  enabled  = true
  blocking = true

  settings {
    name                 = "Release"
    author_id            = azuredevops_user_entitlement.example-entitlement.id
    invalidate_on_update = true
    applicability        = "conditional"
    display_name         = "PreCheck"

    scope {
      repository_id  = azuredevops_git_repository.example-import.id
      repository_ref = "refs/heads/test-branch"  # 替换为目标非默认分支的完整引用
      match_type     = "Exact"
    }
  }
}

关键说明

  • Azure DevOps中分支的合法引用格式为refs/heads/[分支名],直接填写分支名会导致匹配失败。
  • 若需将策略应用到多个非默认分支,可添加多个独立的scope块,每个块对应一个分支的配置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 11:50:19