Reputation: 81
So far I have used this code to grab our azure devops project data. I have poked around the data and any urls returned looking for data related to pipelines and found nothing
string credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken)));
ListofProjectsResponse.Projects viewModel = null;
//use the httpclient
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://acme.visualstudio.com"); //url of our account
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);
HttpResponseMessage response = client.GetAsync("/DefaultCollection/_apis/projects?stateFilter=All&api-version=1.0").Result;
//check to see if we have a succesfull respond
if (response.IsSuccessStatusCode)
{
//set the viewmodel from the content in the response
viewModel = response.Content.ReadAsAsync<ListofProjectsResponse.Projects>().Result;
}
}
public class ListofProjectsResponse
{
public class Projects
{
public int count { get; set; }
public Value[] value { get; set; }
}
public class Value
{
public string id { get; set; }
public string name { get; set; }
public string description { get; set; }
public string url { get; set; }
public string state { get; set; }
}
}
Upvotes: 0
Views: 356
Reputation: 81
The way I found is to enumerate the builds for each project using the same code as above except
HttpResponseMessage response = client.GetAsync("/{org name}/{project
name}/_apis/build/builds?api-version=5.1").Result;
The url for each build will return a json collection with any azure build pipline data inside of "queue"
Upvotes: 0
Reputation: 18978
Did some changes on your main work code and share it below, just have a try:
string credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", "{PAT}")));
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://acme.visualstudio.com"); //url of our account
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);
//HttpResponseMessage response = client.GetAsync("/_apis/projects?stateFilter=All&api-version=1.0").Result;
using (HttpResponseMessage response = await client.GetAsync("/ForMerlin/_apis/projects"))
{
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
// Console.WriteLine(response);
}
For BaseAddress
, what you were using is an old URL format which like https://{org name}.visualstudio.com
. This URL format has contain the organization name in it, so you can ignore the organization name
when calling GetAsync
. Just make it be /_apis/projects?stateFilter=All&api-version=1.0
is okay.
Upvotes: 1