Azure devops 在DevOps中枚举项目时,是否有方法确定项目上是否存在管道?

Azure devops 在DevOps中枚举项目时,是否有方法确定项目上是否存在管道?,azure-devops,Azure Devops,到目前为止,我已经使用此代码获取了我们的azure devops项目数据。我已经搜索了数据和返回的URL,寻找与管道相关的数据,但什么也没找到 string credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", personalAccessToken))); ListofProjectsResponse.Projects viewMod

到目前为止,我已经使用此代码获取了我们的azure devops项目数据。我已经搜索了数据和返回的URL,寻找与管道相关的数据,但什么也没找到

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; }
        }

    }
string credentials=Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format(“{0}:{1},”,personalAccessToken));
ListofProjectsResponse.Projects viewModel=null;
//使用httpclient
使用(var client=new HttpClient())
{
client.BaseAddress=新Uri(“https://acme.visualstudio.com“”;//我们帐户的url
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(新的System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(“应用程序/json”);
client.DefaultRequestHeaders.Authorization=新的AuthenticationHeaderValue(“基本”,凭证);
httpresponsemessageresponse=client.GetAsync(“/DefaultCollection/_api/projects?stateFilter=All&api version=1.0”)。结果;
//查看我们是否有成功的回复
if(响应。IsSuccessStatusCode)
{
//根据响应中的内容设置viewmodel
viewModel=response.Content.ReadAsAsync().Result;
}
}
项目响应的公共类列表
{
公共类项目
{
公共整数计数{get;set;}
公共值[]值{get;set;}
}
公共阶级价值
{
公共字符串id{get;set;}
公共字符串名称{get;set;}
公共字符串说明{get;set;}
公共字符串url{get;set;}
公共字符串状态{get;set;}
}
}

对您的主要工作代码做了一些更改,并在下面分享,请尝试一下:

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);

            }



对于
BaseAddress
,您使用的是一种旧的URL格式,如
https://{org name}.visualstudio.com
。此URL格式包含组织名称,因此在调用
GetAsync
时可以忽略
organization name
。只要让它成为
/\u api/projects?stateFilter=All&api version=1.0
就可以了。

我发现的方法是使用与上面相同的代码枚举每个项目的构建,除了

HttpResponseMessage response = client.GetAsync("/{org name}/{project 
name}/_apis/build/builds?api-version=5.1").Result;

每个构建的url都将返回一个json集合,其中包含“队列”中的任何azure构建管线数据。

这似乎是一个旧版本的API。你确定你的目标是Azure DevOps吗。您可以添加您用来编写此代码的文档引用吗?感谢代码更新,但没有解决问题issue@Theo真的吗?通过上面的代码,我可以获得我组织的所有项目数据,请参见屏幕截图。除非我忽略了一些东西,否则当我获取JSON时,我在项目中没有看到任何构建管道的迹象。当我拉取项目的构建列表时发现了它,如下所述。