簡體   English   中英

azure-devops python 運行“create_work_item”時出錯

[英]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選項

https://github.com/microsoft/azure-devops-python-api/blob/master/azure-devops/azure/devops/v5_1/work_item_tracking/work_item_tracking_client.py#L1578

: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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM