How to Publish an npm Package in Azure Pipelines
Azure Pipelines authenticates npm with the npmAuthenticate task, then npm publish targets a feed or npmjs.
Run npmAuthenticate@0 against your .npmrc (which points at an Azure Artifacts feed or npmjs with a service connection), then npm publish.
Authenticate then publish
The task injects credentials into your committed .npmrc; publish then targets the configured registry.
azure-pipelines.yml
steps:
- task: NodeTool@0
inputs: { versionSpec: '20.x' }
- script: npm ci
- task: npmAuthenticate@0
inputs:
workingFile: .npmrc
- script: npm publish
displayName: PublishGotchas
npmAuthenticatereads a committed.npmrcand injects auth - the registry URL must already be set there.- For an Azure Artifacts feed, the pipeline's build service identity needs Feed Publisher (Contributor) permission.
- For npmjs, add a service connection (or
customEndpoint) so the task knows which external registry credential to use.
Related guides
How to Publish an npm Package in GitHub ActionsPublish an npm package from GitHub Actions on a release - set up the registry with the auth token, run npm pu…
How to Deploy on a Tag in Azure PipelinesTrigger an Azure Pipelines deploy on a tag with trigger.tags and gate the deploy stage by checking Build.Sour…