[英]How not to create duplicates in a task "Create work item" in azure devops
[英]azure-devops python error running 'create_work_item'
我正在尝试使用 azure-devops python pip package 将大量史诗/故事/专题票迁移到 Azure Devops。 我可以很好地创建单个票证,但我无法通过指定层次结构将这些票证链接在一起(票证 A 是父票证到子票证 B / C / D)
为了创建 EPIC 票证,我正在运行如下代码:
#set field
jpo = JsonPatchOperation()
jpo.from_ = None
jpo.op = "add"
jpo.path = "/fields/Microsoft.VSTS.Scheduling.FinishDate"
jpo.value = default_field
jpos.append(jpo)
#create work item
createdWorkItem = wit_client.create_work_item(
document=jpos,
project=project.id,
type="EPIC",
validate_only=validate_only,
bypass_rules=bypass_rules,
suppress_notifications=suppress_notifications
)
这行得通,但现在我想弄清楚如何给这张 Epic 门票一张链接的儿童门票。
在这个 azure-devops python package 的 github 回购中,我可以看到在create_work_item
的定义中有一个字符串变量expand
,它有一个Relations
选项
:param str expand: The expand parameters for work item attributes. Possible options are { None, Relations, Fields, Links, All }.
官方 azure-devops 文档中也讨论了 create_work_item function: https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work-items/create?view=azure-devops-rest -6.0#workitemexpand
但是,如果我将expand='Relations'
添加到我的代码中,则会导致错误:
createdWorkItem = wit_client.create_work_item(
document=jpos,
project=project.id,
type="EPIC",
validate_only=validate_only,
bypass_rules=bypass_rules,
suppress_notifications=suppress_notifications,
expand='Relations'
)
TypeError: WorkItemTrackingClient.create_work_item() got an unexpected keyword argument 'expand'
我是否正确使用了这个“扩展”变量? 或者我应该使用 python 向 azure 中的史诗添加儿童票的不同方法吗? 谢谢
谢谢用户 Shamrai Aleksander - Stack Overflow 。 将您的建议作为答案发布,以帮助其他社区成员。
要解决此TypeError: WorkItemTrackingClient.create_work_item() got an unexpected keyword argument 'expand'
错误:
您可以 append patch_document
中的关系,而不是使用expand
。 您可以试试这个示例:
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
from azure.devops.v6_0.py_pi_api import JsonPatchOperation
import pprint
#Fill in with your personal access token and org URL
personal_access_token = '<pat>'
organization_url = 'https://dev.azure.com/<org>'
#Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
#Get a client (the "core" client provides access to projects, teams, etc)
wi_client = connection.clients.get_work_item_tracking_client()
parent_id = 2129
child_id = 2217
parent_work_item = wi_client.get_work_item(parent_id);
pprint.pprint(parent_work_item.url)
patch_document = []
patch_document.append(JsonPatchOperation(op='add',path="/relations/-",value={"rel": "System.LinkTypes.Hierarchy-Reverse","url": parent_work_item.url}))
wi_client.update_work_item(patch_document, child_id)
参考资料: Azure Python 如何将儿童/相关门票链接到已创建的门票? - 堆栈溢出和GitHub - microsoft/azure-devops-python-api:Azure DevOps Python API
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.