I am attempting to use the vsts-node-api package in a custom Build task that I am writing and trying to use on on-prem tfs2017. I have leveraged some of the Sample code found on the github repo, and I've found that it returns an error of Invalid Resource. Doing some debugging in VSCode and then adding some debug logging to the rest code, I find that the rest call returns a 401. The error occurs after I get the WebApi and then try to connect.
I've attempted to use the PAT Handler, and the NtlmHandler, but no luck. If I hit the URI through my browser, I successfully get the JSON returned.. any help would be super appreciated.
export async function getWebApi(pwd:string): Promise<vm.WebApi> {
return new Promise<vm.WebApi>(async (resolve, reject) => {
try {
console.log("in the common getter");
let serverUrl = 'https://mylocalserver/tfs/mycollection';
let token = ' my PAT on the server, that has full access ';
let authHandler = vm.getPersonalAccessTokenHandler(token);
let option = {
ignoreSslError: true
};
let vsts: vm.WebApi = new vm.WebApi(serverUrl, authHandler,options);
console.log("got web api?");
let connData: lim.ConnectionData = await vsts.connect();
console.log('Hello ' + connData.authenticatedUser.providerDisplayName);
resolve(vsts);
}
catch (err) {
console.log("error in get api " + err.message);
reject(err);
}
});
thanks
It looks like this response from the VSTFS team is the way to go.
TLDR; Generate a bearer OAuth token per build to talk back to VSTS.