How to get build definitions from TFS using REST API in VSTS widgets?

I am trying to get all existing build definitions on a TFS 2015 Update 3 server using the REST API from the Microsoft VSTS SDK as a panel widget:

VSS.init({                        
    explicitNotifyLoaded: true,
    usePlatformStyles: true
});

VSS.require("TFS/Dashboards/WidgetHelpers", "TFS/Build/RestClient", "VSS/Authentication/Services"],
    function (WidgetHelpers, TFS_Build_Api) {
    VSS.register("BuildStatusMonitor.Configuration", function () {

        return {
            load: function (widgetSettings, widgetConfigurationContext) {
                var buildClient = TFS_Build_Api.getClient();
                buildClient.getDefinitions().then(function(definition) {
                    //
                }, function(reason) {
                    // 401
                });
            },
        }
    });
    VSS.notifyLoadSucceeded();
});

Sorry, I always get

TFS.WebApi.Exception: TF400813: The resource is not available for anonymous access. Client authentication required.

What am I doing wrong?

When I send a receive request to the Chrome Developer Console, I get the correct answer: = /

$. get ("http: // *****: 8080 / tfs / TestReporting / DashboardWidgets / _apis / build / definitions? api-version = 2.2") .success (function (res) {console.log (res)})

+4
source share
2

TFS REST API.

VSTS TFS , PowerShell.

TFS script ( ) PowerShell PSCredential -Credential REST. , :

$securePassword = $Password | ConvertTo-SecureString -AsPlainText -Force   $credential = New-Object System.Management.Automation.PSCredential($User, $securePassword)       
$releaseresponse = Invoke-RestMethod -Method Get -Credential $credential -ContentType application/json -Uri $Uri
0

Source: https://habr.com/ru/post/1652032/


All Articles