簡體   English   中英

是否有 TFS 的 REST API 在沒有 Z3A580F1422036773F5B30898 的情況下運行?

[英]Is there a REST API for TFS that functions without Azure DevOps?

我被指派為 DevOps 構建一組工具,以縮短我們在構建多個分支時的周轉時間。 這些工具需要與我們當前在 Team Foundation Server 上運行的源代碼控制進行交互。 When I asked if we had access to Azure DevOps, which according to the tutorials I found online was needed to create an authentication token that could be used to access TFS through it's default REST API, I was told that we did not and had no plans到,因為這家公司是 AWS 組織。

Does anyone know if there's a way to access a REST or similar API for TFS if all you have access to is TFS running on AWS?

是的,如評論中所述,您應該使用PAT通過 Rest API 對 TFS 進行身份驗證。 用戶名應為空。 PAT 是密碼。 google 中有多個相關教程,示例供您參考:

using System.Net.Http;
using System.Net.Http.Headers;

...

//encode your personal access token                   
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://{accountname}.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); 

    //connect to the REST endpoint            
    HttpResponseMessage response = client.GetAsync("_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;

        //var value = response.Content.ReadAsStringAsync().Result;
    }   
}

由於您將 PAT與本地 TFS 服務器一起使用,請確保您已關閉服務器上的基本身份驗證 否則你會得到一個返回的錯誤。

我們建議您在使用 Azure DevOps 服務器時始終關閉 IIS 基本身份驗證。 只有在必要時才應啟用 IIS 基本身份驗證。 在 windows 計算機上啟用 IIS 基本身份驗證時,它會阻止您使用個人訪問令牌 (PAT) 作為身份驗證機制。

源鏈接

此外,我們確實與 AWS 有很好的集成。 我們可以從 Azure DevOps/TFS 端調用 AWS 服務。 還可以使用 AWSCLI 和 AWS Powershell 模塊。 如果您需要,有關更多詳細信息,請查看此鏈接——AWS Tools for Microsoft Visual Studio Team Services/TFS

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM