2
votes

Setup
I have created a new project using dotnet new react.
My code is on Azure DevOps GIT.
I am using a npm module published on a private registry in the same ADO organization.

Issue
In my build pipeline, my dotnet publish task fail with the following error

npm ERR! code E401
  npm ERR! Unable to authenticate, need: Bearer authorization_uri=https://login.windows.net/xxxxxxxxxxxxxxxx, Basic realm="https://xxxxxxxxxxx.pkgs.visualstudio.com/", TFS-Federated
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     C:\npm\cache\_logs\2020-10-23T16_16_30_880Z-debug.log
D:\a\1\s\Portal.csproj(48,5): error MSB3073: The command "npm install" exited with code 1.

Things I have tried

  1. Added an npm authentciate task before the dotnet publish task. That task passes but I get the 401 error in the publish task.
1

1 Answers

0
votes

NPM authentication with private feeds fails for dotnet publish on ADO pipeline

According to the npm Authenticate task (for task runners):

Use this task to provide npm credentials to an .npmrc file in your repository for the scope of the build. This enables npm, as well as npm task runners like gulp and Grunt, to authenticate with private registries.

SO, it not work with dotnet publish task. To resolve this issue, you could try to use npm task, like npm install to restore the packages and npm build to build the project, then use the Azure App Service deploy to publish the react project.

You could check this blog for some more details.