Integrate VSTS 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 VSTS, so if you would like to update tickets from VSTS 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 VSTS

VSTS doesn't also provide any tools to integrate with Youtrack either, so to update tickets from VSTS, we need to use the REST API. VSTS has a "native" support for azure functions, so linking VSTS 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.

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 = new BearerTokenConnection("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 VSTS

To call a Azure Function from VSTS, 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, VSTS calls our Azure Function, which updates all the "Waiting for Deployment" tickets into "Deployed" state.



9 comments:

  1. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here
    Thank you. Your blog was very helpful and efficient For Me,Thanks for Sharing the information Regards Azure Online Course

    ReplyDelete
  2. As you have now understood the usage of ‘Record and Playback’ tool, the following are the different posts using which you can explore the functioning of ‘Selenium IDE’
    selenium Training in chennai

    ReplyDelete

  3. Robotic Process Automation (RPA) is one of the most exciting developments in Business Process Management (BPM) in recent history. Some industry experts believe it may be even more transformational than cloud computing transformational than cloud Automationminds team. (RPA)Automationminds lets you program in (RPA),
    Robotic Process Automation course

    ReplyDelete
  4. SQream Technologies provides you with a state of the art software which combines modern GPU technology (Graphic Processing Units) with the best practices in today’s Big Data platforms, providing up to 100x faster insights from data.
    Bigdata Training in Chennai OMR

    ReplyDelete
  5. As you have now understood the usage of ‘Record and Playback’ tool, the following are the different posts using which you can explore the functioning of ‘Selenium IDE’
    selenium Training in chennai

    ReplyDelete
  6. SQream Technologies provides you with a state of the art software which combines modern GPU technology (Graphic Processing Units) with the best practices in today’s Big Data platforms, providing up to 100x faster insights from data.
    Bigdata Training in Chennai OMR

    ReplyDelete
  7. As you have now understood the usage of ‘Record and Playback’ tool, the following are the different posts using which you can explore the functioning of ‘Selenium IDE’
    selenium Training in chennai

    ReplyDelete
  8. SQream Technologies provides you with a state of the art software which combines modern GPU technology (Graphic Processing Units) with the best practices in today’s Big Data platforms, providing up to 100x faster insights from data.
    Bigdata Training in Chennai OMR

    ReplyDelete
  9. As you have now understood the usage of ‘Record and Playback’ tool, the following are the different posts using which you can explore the functioning of ‘Selenium IDE’
    selenium Training in chennai

    ReplyDelete