Publish npm packages with Azure Pipelines (YAML/Classic)

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019

With Azure Pipelines, you can publish your npm packages to Azure Artifacts feeds and public registries like npmjs.com. This article will guide you through publishing your npm packages using both YAML and Classic pipelines.

Prerequisites

Publish to Azure Artifacts feeds

Note

To publish your packages to a feed using Azure Pipelines, ensure that both the Project Collection Build Service and your project's Build Service identity are configured as a Feed Publisher (Contributor). See Add new users/groups for more details.

- task: Npm@1
  inputs:
    command: publish
    publishRegistry: useFeed
    publishFeed: <FEED_NAME>        ## For project-scoped feeds, use: <PROJECT_NAME>/<FEED_NAME> 
  • publishRegistry: select useFeed to use a feed within your organization. Options: useExternalRegistry, useFeed
  • publishFeed: the feed you want to publish to. Required when publishRegistry = useFeed.

Tip

When adding the npm task to your YAML pipeline using the YAML editor, the project and feed IDs for your publishFeed will be generated automatically.

Publish to a public registry

Before publishing your packages to a public npm registry like npmjs.com, you must first create a service connection to authenticate with the desired external service.

  1. Sign in to your Azure DevOps organization, and then navigate to your project.

  2. Select Project settings > Service connections, and then select Create service connection.

    A screenshot that shows how to create a new service connection in Azure DevOps.

  3. Select npm and then select Next. Fill out the required fields, and then select Save when you're done.

- task: Npm@1
  inputs:
    command: publish
    publishRegistry: useExternalRegistry
    publishEndpoint: '<NAME_OF_YOUR_SERVICE_CONNECTION>'
  • publishRegistry: select useExternalRegistry to publish to a public registry. Options: useExternalRegistry | useFeed.
  • publishEndpoint: replace the placeholder with the name of the service connection you created earlier. required when publishRegistry == useExternalRegistry.