从扩展中访问VSTS服务端点凭据

时间:2016-08-04 13:56:51

标签: azure-devops

我正在开发VSTS扩展程序。 我已通过门户配置了VSTS服务端点。 我需要在扩展代码中使用已配置端点的凭据。 有人知道怎么做吗?

- 提前谢谢。

2 个答案:

答案 0 :(得分:1)

您需要将要使用的服务端点添加到构建扩展的task.json中,然后才能在构建任务中使用它。有关详细信息,请参阅此链接:Service Endpoints in Team Services

您还可以查看GitHub中的VSTS Agent Task,了解如何在this one等构建任务中使用服务端点。

答案 1 :(得分:0)

感谢Eddie,

我在你的帮助下找到了解决方案, 我正在使用0.5.8版本的vsts-task-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.
相关问题