Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vsts-npm-auth can't get authentication token on VSTS build

I'm attempting to use vsts-npm-auth to get the authentication token for our VSTS package repository. On my development machine I can run the commands

npm install -g vsts-npm-auth vsts-npm-auth -config path-to-my\.npmrc

and it succeeds in providing me with an authentication token. I'm now trying to recreate this as a build step on VSTS, so I create the powershell script auth-vsts.ps1

$npmrcFile = "$PSScriptRoot\path-to-my\.npmrc";
npm install -g vsts-npm-auth;
vsts-npm-auth -config $npmrcFile;

and add it as a powershell task. However, the task fails as follows

2017-05-30T09:37:41.1082686Z ##[section]Starting: auth-vsts
2017-05-30T09:37:41.1092712Z ==============================================================================
2017-05-30T09:37:41.1092712Z Task         : PowerShell
2017-05-30T09:37:41.1092712Z Description  : Run a PowerShell script
2017-05-30T09:37:41.1092712Z Version      : 1.2.3
2017-05-30T09:37:41.1092712Z Author       : Microsoft Corporation
2017-05-30T09:37:41.1092712Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
2017-05-30T09:37:41.1092712Z ==============================================================================
2017-05-30T09:37:41.1112679Z ##[command]. 'd:\a\1\s\auth-vsts.ps1' 
2017-05-30T09:37:47.3792461Z C:\NPM\Modules\vsts-npm-auth -> C:\NPM\Modules\node_modules\vsts-npm-auth\bin\vsts-npm-auth.exe
2017-05-30T09:37:47.3792461Z C:\NPM\Modules
2017-05-30T09:37:47.3802239Z `-- [email protected] 
2017-05-30T09:37:47.3802239Z 
2017-05-30T09:37:47.3802239Z 
2017-05-30T09:37:47.3802239Z vsts-npm-auth v0.25.0.0 
2017-05-30T09:37:47.3802239Z -----------------------
2017-05-30T09:37:47.3802239Z Creating npmrcFile. Path: D:\a\1\s\.npmrc
2017-05-30T09:37:47.3802239Z Getting new credentials for source:https://our-domain/_packaging/SharedLib/npm/registry/, scope:vso.packaging_write vso.drop_write
2017-05-30T09:37:49.8729702Z Caught exception: The prompt option is invalid because the process is not interactive.
2017-05-30T09:37:49.8729702Z Parameter name: PromptType
2017-05-30T09:37:49.8729702Z Caught exception: The prompt option is invalid because the process is not interactive.
2017-05-30T09:37:49.8729702Z Parameter name: PromptType
2017-05-30T09:37:49.8729702Z Couldn't get an authentication token for //our-domain/_packaging/SharedLib/npm/registry/:_authToken.
2017-05-30T09:37:50.1769711Z ##[error]Process completed with exit code 1.
2017-05-30T09:37:50.1809715Z ##[section]Finishing: auth-vsts

The error gives no indication as to why it can't obtain the credentials. Any ideas why this might be?

like image 525
James B Avatar asked Aug 30 '25 18:08

James B


2 Answers

Inside your project, you can open a terminal and run

 vsts-npm-auth -F -C .npmrc

This script refreshes the npm token. Here I set two parameters: -F forces the refresh (if not set, the token is refreshed only if it is already expired), while -C fileName defines the configuration file.

like image 126
Denys Kriukov Avatar answered Sep 03 '25 06:09

Denys Kriukov


I faced this issue while trying to execute via Visual Studio Code`s powershell terminal

vsts-npm-auth -config .npmrc

But running the same command via simple console solved this issue and I was redirected to authentication window.

Can suggest that due to internal limitations powershell disabled to open another windows.

like image 44
Viacheslav Kotsiuba Avatar answered Sep 03 '25 08:09

Viacheslav Kotsiuba