Azure DevOps Rest Api. 1. Connect To The Service

<<Contents

In order to interact with the Azure Devops (VSTS or TFS), you can use several approaches:

  1. Develop your own library through HttpClient that is not complicated, and the example can be found here.
  2. Use existing nugget packages: Microsoft.TeamFoundationServer.Client.

Example of the package installation and the result displayed below.

Figure 1. Search the package for installation

Figure 2. The upgraded project references

Connection through VssConnection may be reached with several methods:

  • Connect to the Azure DevOps Server (TFS) using the current user:

VssConnection connection = new VssConnection(new Uri(ServiceURL), new VssCredentials());

  • Connect to the Azure DevOps Server (TFS) using the custom user and password:

VssConnection connection = new VssConnection(new Uri(ServiceURL), new WindowsCredential(new NetworkCredential(User, Password)));

VssConnection connection = new VssConnection(new Uri(ServiceURL), new VssBasicCredential(string.Empty, PAT));

For further interaction, you have to create clients:

WitClient = Connection.GetClient<WorkItemTrackingHttpClient>();

BuildClient = Connection.GetClient<BuildHttpClient>();

ProjectClient = Connection.GetClient<ProjectHttpClient>();

GitClient = Connection.GetClient<GitHttpClient>();

TfvsClient = Connection.GetClient<TfvcHttpClient>();

TestManagementClient = Connection.GetClient<TestManagementHttpClient>();

The list of the main clients:

  • WorkItemTrackingHttpClient – a client to work with work items.
  • GitClient – a client to work with the Git source code repository.
  • TfvsClient – a client to work with the TFVC source code repository.
  • TestManagementClient – a client to work with test plans, tests, etc.
  • BuildClient – a client to work with builds and build definitions.
  • ProjectClient – a client to work with team projects.

The sample application here: https://github.com/ashamrai/TFRestApi/tree/master/01.TFRestApiApp

 

Russian version