首页 文章

从扩展访问VSTS服务 endpoints 凭据

提问于
浏览
0

我正在开发一个VSTS扩展 . 我已通过门户配置了VSTS服务 endpoints . 我需要在扩展代码中使用已配置 endpoints 的凭据 . 有人知道怎么做这个吗?

-提前致谢 .

2 回答

  • 0

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

    您还可以查看GitHub中的VSTS Agent Task,了解如何在构建任务(如this one)中使用服务 endpoints .

  • 1

    谢谢艾迪,

    我在你的帮助下找到了一个解决方案,我使用了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.
    

相关问题