I followed the official tutorial on deploying Angular app to ADO pipelines and here is my yaml.
# Node.js with Angular
# Build a Node.js project that uses Angular.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- main
pool:
vmImage: ubuntu-latest
steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'
displayName: 'Install Node.js'
- task: npmAuthenticate@0
inputs:
workingFile: '.npmrc'
- script: |
npm install -g @angular/cli
npm install
ng build --prod
displayName: 'npm install and build'
But the pipeline fails at npm install with the following error:
npm ERR! code E401
npm ERR! Unable to authenticate, your authentication token seems to be invalid.
The app is running locally but it fails in the pipeline. For context, the app uses libs from external organization’s feeds and locally I put my credentials in .npmrc in the user directory and .npmrc with registries in the project directory.
I have tried placing .npmrc with the registries used in the repo’s root directory, I have also tried using my user .npmrc and saved it in a variable and later echo’ed it to a .npmrc in the yaml file but none of the above helped me to resolve the issue.
2
Answers
You need to authenticate before you run
npm install
.Make sure to add this step in your pipeline before that.
Azure Artifacts Credential Provider:
This provider is a better alternative to manually handling
.npmrc
files.Other small things to double check that I have run into in the past:
Make sure the
.npmrc
file in the root references the feed URLs correctly with correct syntax.If the packages are in the Azure Artifacts feed from a different Azure DevOps organization than your current organization where you pipeline is in, you can set the outside feed as an upstream source of the feed within the current organization.
Then normally, if the pipeline has the access to the feed within the current organization, it also can access the packages from its upstream source feed.
More details, see "Configure upstream sources".
If you do not set upstream source, you need to set up a service connection for use on the npmAuthenticate@0 task to connect to the outside feed.