Skip to content

Integrate Azure DevOps with… itself

Azure DevOps offers quite customizable work item flow with custom work item cards, rules and processes, but sometimes you want something extra, that built-in solutions cannot give you.

One of the case is to update parent work item when child work item updates. For example when all the tasks are moved to closed state, the user story should be closed also. Currently there is no built-in way to achieve this, but luckily we can always build our own solution.

Microsoft has provided Microsoft.TeamFoundationServer.ExtendedClient library to interact with Azure DevOps (later ADO).

Connection is simply done with VssBasicCredentials and xxHttpClient classes. Connection can be done with Personal Azure DevOps token, which is created at security tab. Security tab can be found by clicking top right corner icon (typically with your name letters in it). 

var credentials = new VssBasicCredential(string.Empty, "(personal Azure DevOps token");
var client = new Microsoft.TeamFoundation.WorkItemTracking.WebApi.WorkItemTrackingHttpClient(new System.Uri(@"https://companyname.visualstudio.com/"), credentials);

Service Hooks

Under Project Settings we can setup Service hooks, which can be used to trigger custom actions based on actions like pull requests, work item updates and so forth.

Depending on selected event, ADO will send different kind of JSON payloads. Quick way to manage payloads is to just setup service hook, click Test button, copy example payload from Event tab and paste it into json2csharp.com to generate C# classes from it.

Azure Functions

Currently Azure Functions are the best way to build small scale integrations. Latest 2.0 version has a really solid tooling for Visual Studio Code, so development is fast and easy. After installing Azure Functions extension, azure functions can be created, updated and deleted directly from Visual Studio Code.

Azure Functions and C# extensions are solid tools for Azure Functions development.

Http trigger types of Azure Functions can be called directly from ADO. Only access token from Azure Portal is required and thats all. 

If you are using Azure Function 2.0 just remember to add method name and Azure Function token (from portal) into service hook url:
http://…/api/(methodname)?code=(Azure Function token)