Skip to content
Latchkey

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: Publish

Gotchas

  • npmAuthenticate reads a committed .npmrc and 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

Run this faster and cheaper on Latchkey managed runners. Start free →