1 | initial version |
To add a comment using the Python API in Azure DevOps, you can use the following code:
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
# Your organization URL
organization_url = 'https://dev.azure.com/myOrganization'
# Personal access token for authentication
personal_access_token = 'myToken'
# Create a connection to the Azure DevOps organization
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
# The team project where the work item is located
team_project = 'MyProject'
# The ID of the work item
work_item_id = 1234
# The comment text
comment_text = 'This is a comment'
from azure.devops.v6_0.work_item_tracking import WorkItemTrackingHttpClient
from azure.devops.v6_0.work_item_tracking.models import CommentCreate
# Get a reference to the WorkItemTrackingHttpClient
wit_client = connection.clients.get_work_item_tracking_client()
# Create a CommentCreate object with the comment text
comment = CommentCreate(text=comment_text)
# Add the comment to the work item
wit_client.add_comment(comment, team_project, work_item_id)
This will add a new comment to the specified work item in Azure DevOps using the Python API.