Import from JIRA to VSTS in 5 steps

In previous posts I documented some features of VSTS and a few scenarios of Application Lifecycle Management.

If you like VSTS it’s likely that you want to move your existing project from your current platform to VSTS. I’m currently planning a migration from JIRA to VSTS at work and here I am to share my findings.

This blog post has been inspired by the work of the ALM DevOps Rangers.

We’re going to build a simple tool to migrate and map Jira issues into VSTS items.

The source code is available on GitHub.

1. Create a .NET Console App

We start by creating a new console app with Visual Studio.

1.jpg

2. Import NuGet packages

We use someNuGet packages to access JIRA and VSTS API more easily.

  • Atlassian.SDK
  • Microsoft.VisualStudio.Services.Client
  • Microsoft.TeamFoundationServer.Client

This slideshow requires JavaScript.

3. Connection to VSTS

Now we have all the tools we need.
We can start to connect to VSTS and we do that by creating a PAT (Personal Access Token – to create a PAT see section 3 here).
To connect to VSTS we need to create a connection and then a client based on that connection. This is the code:

VssConnection connection = new VssConnection(new Uri(Settings.Default.VstsURL), new VssBasicCredential(string.Empty, Settings.Default.VstsPAT));
            using (WorkItemTrackingHttpClient witClient = connection.GetClient())
            {
                //work... work... work...
            }

4. Connection to Jira

Now we need to connect to Jira and we can do this with che classes that are present in the Atlassian.Jira package we’ve just imported.

Jira jiraConn = Jira.CreateRestClient(Settings.Default.JiraURL, Settings.Default.JiraUser, Settings.Default.JiraPassword);

            var issues = (from i in jiraConn.Issues.Queryable orderby i.Created select i).ToList();

5. Import from Jira to VSTS

Now it’s time to get the real work done and we need to query Jira for issues that we want to iterate and create work items in VSTS.
Our strategy is to query Jira and for each issue we copy the values of our interests into a new work item of VSTS. In the following example we create work items of type User Story and assign values to the Title, Description, Created By, and Story Points fields.

static void Main(string[] args)
        {
            VssConnection connection = new VssConnection(new Uri(Settings.Default.VstsURL), new VssBasicCredential(string.Empty, Settings.Default.VstsPAT));
            using (WorkItemTrackingHttpClient witClient = connection.GetClient())
            {
                Jira jiraConn = Jira.CreateRestClient(Settings.Default.JiraURL, Settings.Default.JiraUser, Settings.Default.JiraPassword);

                var issues = (from i in jiraConn.Issues.Queryable
                              orderby i.Created
                              select i).ToList();

                foreach (var issue in issues)
                {
                    JsonPatchDocument document = new JsonPatchDocument();
                    string title = $"{issue.Key} - {issue.Summary}";
                    title = title.Substring(0, Math.Min(title.Length, 128));
                    document.Add(new JsonPatchOperation { Path = "/fields/System.Title", Value = title });
                    if (issue.Description != null)
                    {
                        document.Add(new JsonPatchOperation { Path = "/fields/System.Description", Value = issue.Description });
                    }

                    JiraUser user = jiraConn.Users.SearchUsersAsync(issue.Reporter).Result.FirstOrDefault();
                    if (user != null)
                    {
                        document.Add(new JsonPatchOperation { Path = "/fields/System.CreatedBy", Value = user.Email });
                    }

                    var x = issue.CustomFields["Story points"]?.Values.FirstOrDefault() ?? "";
                    if (x != "")
                    {
                        document.Add(new JsonPatchOperation { Path = "/fields/Microsoft.VSTS.Scheduling.StoryPoints", Value = x });

                    }

                    const string project = "xxxxx";
                    const string workItemType = "User Story";
                    var workItem = witClient.CreateWorkItemAsync(document, project, workItemType).Result;
                }
            }
        }

TL;DR

With this blog post we’ve seen how to build a simple tool to migrate issues from Jira into VSTS as work items. This has been done with the help of Atlassian and Microsoft libraries to access their system with ease.

Reference

.NET Client libraries for VSTS (and TFS) (https://docs.microsoft.com/it-it/vsts/integrate/concepts/dotnet-client-libraries?view=vsts)
Atlassian SDK Wiki (https://bitbucket.org/farmas/atlassian.net-sdk/wiki/Home)
VSTS fields (https://docs.microsoft.com/en-us/vsts/work/work-items/guidance/work-item-field?view=vsts)

2 thoughts on “Import from JIRA to VSTS in 5 steps

  1. Hi There,

    Amaze! I have been looking bing for hours because of this and i also in the end think it is in this article! Maybe I recommend you something helps me all the time?

    They are mapping variables and workflow variables. I have created them in the mapping and assigned the value in the mapping. Created the in the workflow and assigned the mapping variables to the workflow variables. They are not set to persistent. I need the values to get refreshed every time I run the workflow. Informatica PIM Training USA .
    Thanks a lot. This was a perfect step-by-step guide. Don’t think it could have been done better.

    Thanks,
    Preethi.

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.