Ask Your Question
2

How can a comment be added using the Python API in Azure DevOps?

asked 2023-05-28 02:03:12 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-28 02:13:01 +0000

bukephalos gravatar image

To add a comment using the Python API in Azure DevOps, you can use the following code:

  1. First, import the necessary modules and authenticate to the Azure DevOps organization:
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)
  1. Specify the team project and work item ID where you want to add a comment:
# The team project where the work item is located
team_project = 'MyProject'

# The ID of the work item
work_item_id = 1234
  1. Define the comment that you want to add:
# The comment text
comment_text = 'This is a comment'
  1. Use the WorkItemTrackingHttpClient to add the 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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-28 02:03:12 +0000

Seen: 10 times

Last updated: May 28 '23