npm install from tfs feed (on build process) give error: Unable to authenticate
Asked Answered
P

2

6

We have our own npm package and a project that uses it, I want to publish it to a tfs feed - repository and install it from there instead of from a physical file.

I published the package to the feed from my development machine,
and I changed the reference within the project that consumes it.

The whole process works fine from my machine, but when I try to consume the package on a build process in the tfs - it fails with the error :

Unable to authenticate, your authentication token seems to be invalid.

I've created .npmrc file at the project level with the registry address, and another file with credentials on the user directory, and I did the same on the TFS machine.

What can cause the npm install (from my feed) to not work on the tfs machine?

EDIT:
When I add prefix @my to the registry at the user-level .npmrc file - like this:

@my:registry=https://my-feed-address

The error changes to: "No valid versions available for my-package"

Pringle answered 30/6, 2019 at 11:55 Comment(15)
The build agent run with user, give to this user permissions in the feed.Onomatopoeia
@ShaykiAbramczyk, Do you mean Feed settings->Permissions ? If so, this user has owner permission.Pringle
Can you share your build pipeline?Onomatopoeia
@ShaykiAbramczyk, I do not think that's the point, Because even when I run the npm install command in the tfs server - in the project folder within the relevant 's' folder - I get the same behavior. + I edited my question.Pringle
Which version of TFS is it? Are you using the npm install task? it has and authentication section that you can point to your .npmrc file. There is also a npm authenticate task you might want to run first.Launcelot
@Etienne, It was the 2017 version, and we upgraded it to the 2019 version to solve this problem but it did not help. I tried both the 'Registries in my .npmrc' option and the 'Registry I select here' option, with\without selection of a Service connection which I created that connects to my feed. But, as I wrote in the previous comment, why it would work if running this command inside the tfs server in command line - it does not work? (I do not know why) I get the same error.Pringle
why do you think running it inside tfs server should skip auth?Spirogyra
Try adding a variable system.debug with a value of true you’ll get more information in the failure. That might help pinpoint the problemLauncelot
@4c74356b41, When I run it inside the server - it should use the configuration an auth token listed in the npmrc file on the server, and it should succeed as it does from my machine, but it fails...Pringle
@Etienne, Is system.debug a variable of the process in tfs? What I need is details from the npm.Pringle
why do you think it should do that? also, can you verify the token is working? did you hardcode it?Spirogyra
@4c74356b41, The process runs in this machine. If not from this file - where should it take the settings? How can I verify the token is working? And what do you mean by did you hardcode it?Pringle
@Pringle by adding system.debug value of true, you'll get more info in the task log as to why npm authenticate doesn't work.Launcelot
@Etienne, But it will not give me more details than running the npm install command inside the tfs server in Command Line, is not it?Pringle
It might give you the variables it uses and sometimes other errorsLauncelot
B
8
  1. Install this in machine: npm install -g vsts-npm-auth
  2. Run this (in the directory where npmrc file is): vsts-npm-auth -config .npmrc
Bryson answered 9/7, 2019 at 14:58 Comment(1)
i had the same problem but this solved in my case. in my build pipeline everytime before the restore i execute this vsts-npm-auth -config .npmrc. it works directly in build machine (without build process)? have you tried?Bryson
J
4

Create a file .npmrc in your project folder and add the following

registry=Your URL
always-auth=true

In the command prompt run both of these commands

npm install -g vsts-npm-auth --registry https://registry.npmjs.com --always-auth false

vsts-npm-auth -config .npmrc

Jounce answered 12/11, 2019 at 9:27 Comment(3)
That's only works on Windows according to DevOps' documentation.Tirzah
Does NOT work for ubuntu: cannot execute binary file: Exec format error... possibly this is only for Windows OSMedor
For Windows this did it for me.... You have to enable the script polycies (e.g. Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted Yes )Medor

© 2022 - 2024 — McMap. All rights reserved.