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

能否使用Azure DevOps Python API v7_1创建项目级组?

Azure DevOps Python API v7_1 创建项目级组实现方案

Python API v7_1完全支持创建项目级组,核心就是使用Identity Client的create_groups方法,以下是具体实现步骤和代码示例:

步骤1:初始化客户端连接

先通过个人访问令牌(PAT)建立与Azure DevOps组织的连接,并获取Identity Client实例:

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication

# 配置组织地址和PAT
org_url = "https://dev.azure.com/你的组织名称"
pat = "你的个人访问令牌"

# 建立身份验证和连接
credentials = BasicAuthentication('', pat)
connection = Connection(base_url=org_url, creds=credentials)

# 获取Identity Client
identity_client = connection.clients.get_identity_client()

步骤2:获取目标项目ID

项目级组的scope_id必须是项目的UUID,因此需要先获取对应项目的ID:

from azure.devops.v7_1.core import CoreClient

core_client = connection.clients.get_core_client()
# 替换为你的项目名称
project = core_client.get_project("目标项目名称")
project_id = project.id

步骤3:构造组请求并创建

构造CreateGroupRequest对象,指定组名称、描述、项目ID作为scope,然后调用create_groups方法:

import azure.devops.v7_1.identity as identity

# 组装创建组的请求参数
create_group_req = identity.models.CreateGroupRequest(
    display_name="项目级自定义组",
    description="通过Python API创建的项目权限组",
    scope_id=project_id,
    mail_nickname="proj-custom-group"  # 必填项,不能重复
)

# 执行创建操作
created_group = identity_client.create_groups(create_group_req)

# 输出结果
print(f"项目级组创建成功:ID={created_group.id}, 名称={created_group.display_name}")

注意事项

  • 你的PAT需要具备项目级身份管理权限(可先赋予"项目集合管理员"权限测试,后续再细化)
  • mail_nickname是必填参数,且在组织内不能重复
  • 若需要给组添加成员,可使用Identity Client的add_members_to_group方法,传入组ID和成员ID即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 23:30:12