'Azure Python how to link child/related tickets to an already created ticket?
I am using the Azure Python tool to create Epic/Story/Feature work items in a python script like so:
# add fields
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
)
#save details to local json file
epic_details = {
"op": "add",
"path": "/relations/-",
"value": {
"rel": "System.LinkTypes.Hierarchy-Reverse",
"name": "Parent",
"url": createdWorkItem.url
}
}
I need to link my tickets together, such as adding a Child / Parent relationship between tickets. I'm trying to do this by creating all my tickets first, then linking them all where needed.
Is there some way with the Azure Devops Python tool that I can add a child workitem to a epic workitem if both tickets already exist? Thanks.
edit: I've found the function ParentChildWIMap referenced here:
https://github.com/microsoft/azure-devops-python-api/blob/451cade4c475482792cbe9e522c1fee32393139e/azure-devops/azure/devops/v5_1/work/models.py#L711
But I'm unsure on how to use it
Solution 1:[1]
If you use https://github.com/microsoft/azure-devops-python-api , you can try this sample:
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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Shamrai Aleksander |
