2016-08-04 77 views
0

我正在開發一個VSTS擴展。 我已通過門戶配置了VSTS服務端點。 我需要在我的擴展代碼中使用配置的端點的憑據。 有誰知道如何做到這一點?從分機訪問VSTS服務端點憑證

- 預先感謝。

+0

什麼是您的擴展的類型,構建任務? –

+0

是它的構建擴展。 – Bandara

回答

0

感謝埃迪,

我找到了一個解決方案在您的幫助,我 使用0.5.8版本的VSTS任務-lib庫,並且將其更新到0.9.7,並做了以下內容,

//Import the task lib 0.9.7 
import tl = require('vsts-task-lib/task'); 

//Get the endpoint ID (a guid) 
serverEndpoint = tl.getInput('serverEndpoint', true); 

//Get the enpoint URL for the retrieved end point id and parse it to URL type 
serverEndpointUrl: url.Url = url.parse(tl.getEndpointUrl(this.serverEndpoint, false)); 

//Extract authentication details from url 
serverEndpointAuth = tl.getEndpointAuthorization(this.serverEndpoint, false); 

//Read parameters to variable 
//NOTE: You cant write this data to console, if you do write, it will write //asterisk (****) instead of real values. 

username = this.serverEndpointAuth['parameters']['username']; 
password = this.serverEndpointAuth['parameters']['password']; 

//Pass the variables as parameters. 
1

您需要將要使用的服務端點添加到構建擴展的task.json中,然後才能在構建任務中使用它。有關詳細信息,請參閱此鏈接:Service Endpoints in Team Services

而且您還可以查看GitHub中的VSTS Agent Task以瞭解如何在構建任務中使用服務端點,如this one

+0

嗨Eddie,謝謝你的回覆。我遵循了您通過FTP訪問端點提供的鏈接,但仍無法從端點提取憑據。我得到錯誤「Endpoint not present:undefined」in line serverEndpointUrl:url.Url = url.parse(tl.getEndpointUrl(this.serverEndpoint,false)); 我還將我的帳戶添加爲端點閱讀器。 – Bandara

+0

@BandR你可以分享代碼和task.json,以便我可以檢查問題出在哪裏? –

+0

是否有可能在非構建任務擴展中使用服務端點,如工作項窗體控件? – Flex