In this tutorial, I will be using Visual Studio 2019 to create a Azure Function that Listens to Azure Service Bus Message Queue to update specified field in Work Item Task using Azure DevOps REST API.
Introduction
Azure DevOps Rest API has a lot to offer in terms of customizing your Processes. On this paper I will be demonstrating an Event driven update on a Work Item task to automatically update the remaining hours by submitting a PATCH request to Azure DevOps REST API.
Prerequisite
- Azure DevOps Subscription (You can subscribe for free Basic Plan if you don’t have one)
- Azure DevOps Personal Access Token
- Provisioned Azure Function
- Newtonsoft.Json
Lets Get Started
Go ahead and create a new project in Visual Studio 2019 and Select Azure Function project template.
Generate a Model Class from the event posted by Azure DevOps Web Hook. You can get your sample request in Service Hook Event History. You can use online class generator to automate the conversion, on this tutorial I used quicktype.
On the method Run in your Function Class, I will be adding ExecutionContext to be able to access configuration settings.
According to Azure DevOps REST API documentation, updating a work item requires a request body with the sample JSON below on your HTTP PATCH request. You can convert this into a class object and later on to be serialized in JSON text as a Request Content.
- "op" value normally is set to "add"
- "path" is the field you wanted to be updated, the value can be found on the Service Hook Event History request
- "value" is the literal value you wanted to be submit
One of the required input to be able to submit a PATCH request in your Work Item Task is your personal access token that has a Read and Write Access in work item and added in Authorization request header.