Skip to content

Integrate Azure DevOps with Youtrack

Youtrack is a great issue tracking tool. It’s light weight and has very intuitive UI. These two features makes it a great tool for customer issue reporting. Bad part is, that it currently doesn’t have any support for Azure DevOps, so if you would like to update tickets from
Azure DevOps it doesn’t provide any out of the box solution. However Youtrack has a very easy to use REST API which can used to build custom integration.

Update Youtrack ticket from Azure DevOps

Azure DevOps doesn’t also provide any tools to integrate with Youtrack either, so to update tickets from Azure DevOps, we need to use the REST API. Azure DevOps has a “native” support for azure functions, so linking Azure DevOps into azure function and implementing small function we can easily integrate these two great tools.

Create new Azure Function

First create an new Azure Function project (from Visual Studio) which provides basic building blocks for our integration. By default Azure Function refers Newtonsoft.Json 9.0, which is too old version for our use. Add Newtonsoft.Json version 10.2 Nuget package and YouTrackSharp package (which requires at least version 10 from Newtonsoft.Json).
YouTrackSharp provides some very easy to use functions to interact with Youtrack REST API. It’s a much faster way to implement REST calls than by coding them manually.

First create new Azure Function 2.0 from Visual Studio Code (use extensions). Add YouTrackSharp package into “project”. YouTrackSharp simplifies integration with Youtrack greatly, so I suggest it over the basic REST calls.

Create permanent token from Youtrack

Connection to Youtrack is done with BearerTokenConnection class, with this class we can use permanent token to login into Youtrack and it’s a much better way than using our own user-name and password (which we don’t want to check in into version control).

From Youtrack, click Update personal… link from own profile page to get into authentication page
From Authentication page, switch to Authencation tab and click New token… button


Code that function

After creating a connection with BearerTokenConnection we can call CreateIssueService method to retrieve a service which provides methods to update, delete and create new tickets.

var connection = newBearerTokenConnection(“https://example.myjetbrains.com/youtrack/”,”perm:…”);
var issueService = connection.CreateIssuesService();

With issue service we can iterate all the tickets we want to by providing Youtrack query as a string parameter:

foreach(var issue in await issueService.GetIssues(“State: {Waiting for deployment}”))
{
     await issueService.ApplyCommand(issue.Id, “assigned to me”);
}

Updating issue is done with ApplyCommand call.

Full example code to update all Waiting for deployment tickets into Deployed state.

public static class Function1
{
        [FunctionName(“ChangeYoutrackStatusToDeployed”)]
 public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, “get”, “post”, Route = null)]HttpRequestMessage req, TraceWriter log)
        {
var connection = new BearerTokenConnection(“https://example.myjetbrains.com/youtrack/”,”perm:…”);
 var issueService = connection.CreateIssuesService();
foreach(var issue in await issueService.GetIssues(“State {Waiting for deployment}”))
            {
await issueService.ApplyCommand(issue.Id, “Deployed”);
    }
return req.CreateResponse(HttpStatusCode.OK);
 }
}

Call Azure Function from Azure DevOps

To call a Azure Function from Azure DevOps, we need to add a new agentless phase to our release definition

Agentless phase can contain a Azure Function call which has only two mandatory settings.
1) Set Azure Function url with /api/ChangeYoutrackStatusToDeployed route
2) Add function key (which is created in Azure Portal)

Now when the release definition is run, Azure DevOps calls our Azure Function, which updates all the “Waiting for Deployment” tickets into “Deployed” state.