2016-08-04 81 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