[RPA] Automating Azure DevOps Project, Repository and Work Items Creation through UiPath

Level of Difficulty: Beginner – Intermediate.

This post will assist in automating the creation of projects, repositories and work items in Azure DevOps through UiPath by using the Azure DevOps API.

There are multiple Azure DevOps libraries available on the UiPath Marketplace that make the API calls for you but the aim of this post is to enable developers through understanding how the Azure DevOps API works so that they can make calls that other existing libraries might not cater for.

The Azure DevOps API is documented here.

What are the steps?

The steps that we will be following are:

  1. Create an Azure DevOps Personal Access Token
  2. Create API Body Templates
  3. Create a ‘Create Project’ Workflow
    1. Prepare Template
    2. Make API Call
    3. Deserialise response
  4. Create a ‘Create Repository’ Workflow
    1. Prepare Template
    2. Make API Call
    3. Deserialise response
  5. Create a ‘Create Work Item’ Workflow
    1. Prepare Template
    2. Make API Call
    3. Deserialise response
  6. Create a ‘Link Work Item’ Workflow
    1. Prepare Template
    2. Make API Call
    3. Deserialise response

Deep Dive

Let’s dive deeper into the steps listed above.

Create an Azure DevOps Personal Access Token

Login to Azure DevOps, which you can navigate to from here.

In the top right hand corner of the screen, under User Settings you can access the Personal access tokens option.

Azure DevOps Personal Access Token Generation

Select New Token:

New Personal Access Token

Give your access token a name, select an organisation if you’d like to only grant permission to a specific organisation and set the expiration date of the token. Ensure that you update the personal access token once it has expired.

New Azure DevOps Personal Access Token

Once you’ve clicked Create, copy the personal access token somewhere safe as we will need it when making the API call.

Create API Body Templates

The templates may be stored in a ‘Templates‘ folder within the UiPath solution. We will need two templates, one for projects and one for repositories. These templates hold the JSON template that is needed for the API request.

The ‘new_project_template.json‘ file should contain the following:

{
	"name": "<project_name>",
	"description": "<project_description>",
	"capabilities": {
		"versioncontrol": {
		  "sourceControlType": "Git"
		},
		"processTemplate": {
		  "templateTypeId": "adcc42ab-9882-485e-a3ed-7678f01f66bc"
		}
	}
}

In UiPath we will need to replace ‘<project_name>‘ and ‘<project_description>‘.

The ‘new_repository_template.json‘ file should contain the following:

{
	"name": "<repository_name>",
	"project": {
		"id": "<project_id>"
	}
}

In UiPath we will need to replace ‘<repository_name>‘ and ‘<project_id>‘.

The ‘new_workitem_template.json‘ file should contain the following:

[
	{
		"op": "add",
		"path": "/fields/System.Title",
		"from": null, 
		"value": "<story>"
	},
	{
		"op": "add",
		"path": "/fields/System.AreaPath",
		"from": null, 
		"value": "<project>"
	},
	{
		"op": "add", 
		"path": "/fields/System.IterationPath", 
		"from": null, 
		"value": "<project>\\Iteration 1"
	}, 
	{
		"op": "add",
		"path": "/fields/System.State",
		"from": null,
		"value": "<story_state>"
	}
]

In UiPath we will need to replace ‘<story>‘, ‘<project>‘ and ‘<story_state>‘.

The ‘link_workitem_template.json‘ file should contain the following:

[
	{
		"op": "test",
		"path": "/rev",
		"value": 1
	},
	{
		"op": "add",
		"path": "/relations/-",
		"value": {
			"rel": "System.LinkTypes.Hierarchy-Reverse",
			"url": "https://dev.azure.com/<organisation>/_apis/wit/workItems/<story_id>",
			"attributes": {
				"comment": "<comment>"
			}
		}
	},
	{
		"op": "add",
		"path": "/fields/System.State",
		"from": null,
		"value": "<story_state>"
	}
]

In UiPath we will need to replace ‘<comment>‘, ‘<story_id>‘ and ‘<story_state>‘.

UiPath ‘Create Project’ Workflow

Create a folder in the UiPath solution folder named Projects and within the folder, create a ‘CreateProject.xaml‘ workflow:

Let’s start by adding a ‘Read Text File‘ activity and assigning a few variables:

The NewProjectURL above is assigned the value of https://dev.azure.com/&#8221; + Organisation + “/_apis/projects?api-version=6.0”. The Organisation variable should correspond to your Organisation name in Azure DevOps.

Next, add a Multiple Assign activity to replace the project name and project description placeholder with the appropriate names:

Make sure that the UiPath.Web.Activities library is installed before trying to add the HTTP Request Activity:

The properties of the HTTP Request activity should include the following:

Only the Personal Access Token is used for authentication as a password when using Basic Authentication meaning that the username can be assigned to literally anything and it will still authenticate, as long as the personal access token is valid.

Add the following added as headers:

Now add a ‘Deserialise JSON’ activity:

The ‘Create Project’ sequence should look like this:

UiPath ‘Create Repository’ Workflow

Create a folder in the UiPath solution folder named Repositories and within the folder, create a ‘CreateRepository.xaml‘ workflow:

Let’s start by adding a ‘Read Text File‘ activity and assigning a few variables:

The NewRepositoryURL above is assigned the value of https://dev.azure.com/&#8221; + Organisation + “/” + ProjectID + “/_apis/git/repositories?api-version=6.0”. The Organisation variable should correspond to your Organisation name in Azure DevOps and the Project ID should correspond to the ID of the project in Azure DevOps.

Next, add a Multiple Assign activity to replace the repository name and project ID placeholder with the appropriate names:

Make sure that the UiPath.Web.Activities library is installed before trying to add the HTTP Request Activity:

The properties of the HTTP Request activity should include the following:

Only the Personal Access Token is used for authentication as a password when using Basic Authentication meaning that the username can be assigned to literally anything and it will still authenticate, as long as the personal access token is valid.

Add the following added as headers:

Now add a ‘Deserialise JSON’ activity:

The ‘Create Repository’ sequence should look like this:

The process of creating the Work Items workflows is very similar to the two mentioned above. Therefore, I’ll go through the next two workflows in a little less detail.

UiPath ‘Create Work Item’ Workflow

Create a folder in the UiPath solution folder named Work Items and within the folder, create a ‘CreateWorkItem.xaml‘ workflow:

Let’s start by adding a ‘Read Text File‘ activity and assigning a few variables:

The NewWorkItemURL above is assigned the value of https://dev.azure.com/&#8221; + Organisation + “/” + ProjectID + “/_apis/wit/workitems/$” + Type + “?api-version=6.0”. The Organisation variable should correspond to your Organisation name in Azure DevOps and the Project ID should correspond to the ID of the project in Azure DevOps.

Next, add a Multiple Assign activity to replace the story name, story state and project name placeholder with the appropriate names:

Similar to the Create Project and Create Repository sections above, add a HTTP request activity with the following properties:

Please note that the body format is application/json-patch+json.

Only the Personal Access Token is used for authentication as a password when using Basic Authentication meaning that the username can be assigned to literally anything and it will still authenticate, as long as the personal access token is valid.

Add the following added as headers:

Now add a ‘Deserialise JSON’ activity:

The ‘Create Work Items’ sequence should look like this:

UiPath ‘Link Work Item’ Workflow

Create a workflow named folder ‘LinkWorkItem.xaml‘ in the folder named Work Items. and add a ‘Read Text File‘ activity and assigning a few variables:

The LinkWorkItemURL above is assigned the value of https://dev.azure.com/&#8221; + Organisation + “/” + ProjectID + “/_apis/wit/workitems/” + TaskID + “?api-version=5.0”. The Organisation variable should correspond to your Organisation name in Azure DevOps and the Project ID should correspond to the ID of the project in Azure DevOps. The Task ID should be the ID of the Task you would like to link to the story.

Next, add a Multiple Assign activity to replace the story name, story state and organisation name placeholder with the appropriate names:

Similar to the Create Project and Create Repository sections above, add a HTTP request activity with the following properties:

Please note that the body format is application/json-patch+json.

Only the Personal Access Token is used for authentication as a password when using Basic Authentication meaning that the username can be assigned to literally anything and it will still authenticate, as long as the personal access token is valid.

Add the following added as headers:

Now add a ‘Deserialise JSON’ activity:

The ‘Link Work Items’ sequence should look like this:

The above solution is available on Github

If you have any questions, issues or feedback, drop a comment below or reach out to jacqui.jm77@gmail.com

Published by Jacqui Muller

I am an automation architect by current profession who enjoys dabbling in software development, RPA, IOT, advanced analytics, data engineering and business intelligence. I am aspiring to complete a Master's degree in Computer Science within the next two years. My competencies include a high level of computer literacy as well as programming in various languages. I am passionate about my field of study and occupation as I believe it has the ability and potential to impact lives - both drastically and positively. I come packaged with an ambition to succeed and make the world a better place.

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

%d bloggers like this: