2
votes

We have a private npm registry (library) for our Angular UI because of this we can't run npm install before authenticating the private registry. The registry is in a different Azure organization. When I work on a local machine for the first time, I run this code, (npm install -g vsts-npm-auth --registry https://registry.npmjs.com --always-auth false) and then this code (vsts-npm-auth -config .npmrc), then pop up appear and I need to input my credentials, like username and password after that I can now use npm install to install packages from my private registry.

In azure CI pipe-line there is no user interaction so what I did was, I created a service connection with username(organization username) and password(organization password) and the package URL which I have found in .npmrc file. I then use the service connection in NPM Authenticate Task to authenticate the registry but it throws me an error when npm install run. I have posted the error pic below. Can anyone please help me to authenticate the private registry to install packages. Thanks

enter image description here

enter image description here

enter image description here

1

1 Answers

1
votes

When the npm registry is in a different Azure organization, you should use Personal access token to Authenticate.

Login to the Azure organization where the npm registry resides, Click here to create a Personal Access token with at least readpermission of Packaging scope.

Then choose Authentication Token as the Authentication method, and type in the Personal Access token generated in above step.

enter image description here

Update: As it is described for task npm authenticate (for task runners) in below:

Don't use this task if you're also using the npm task. Provides npm credentials to an .npmrc file in your repository for the scope of the build. This enables npm task runners like gulp and Grunt to authenticate with private registries.

You can configure the authentication service connection in NPM install task directly. See below:

enter image description here