Skip to content

Latest commit

 

History

History
122 lines (79 loc) · 5.18 KB

File metadata and controls

122 lines (79 loc) · 5.18 KB
title ms.custom description services ms.assetid ms.topic ms.date monikerRange recommendations
Publishing npm packages using Azure Pipeline
seodec18, devx-track-js
How to publish your npm packages with Azure Pipelines
vsts
F4C61B91-2C5B-4848-A4BF-B658F549673A
conceptual
07/22/2021
>= tfs-2017
true

Publish npm packages (YAML/Classic)

Azure Pipelines | Azure DevOps Server 2020 | Azure DevOps Server 2019 | TFS 2018 | TFS 2017

Using Azure Pipelines, you can publish your npm packages to Azure Artifacts feeds or to public registries such as npmjs.com. Using the npm task, you can install or publish npm packages as well as run any npm commands.

Publish to Azure Artifacts feeds

::: moniker range=">= azure-devops-2019" To publish your npm packages to Azure Artifacts feeds from your Pipeline, you must first provide a Contributor access to the Project Collection Build Service identity. See Add new users/groups for more details.

Add the npm task to your yaml pipeline as follows to publish your package to your feed.

- task: Npm@1
  inputs:
    command: publish
    publishRegistry: useFeed
    publishFeed: <PROJECT_NAME>/<FEED_NAME>
  • useFeed: select this option to use a feed in the same organization as the build.

::: moniker-end

::: moniker range="< azure-devops-2019" YAML is not supported in TFS. ::: moniker-end

To publish npm packages to your feed, follow the steps below to add and configure the npm task:

  1. From within your pipeline, select the + sign to add a task to your pipeline, then search for the npm task. Select Add to add it to your pipeline.

    :::image type="content" source="./media/add-npm-task.png" alt-text="Screenshot showing how to find and add the npm task":::

  2. Fill out the required fields as follows:

    :::image type="content" source="./media/npm-publish.png" alt-text="Screenshot showing how to configure the npm publish task":::

  • Display name: name of your task.
  • Command: publish
  • Working folder that contains package.json: path to the folder containing the target package.json and .npmrc files. Leave this blank if those files are at the root of your repo.
  • Registry location: select Target registry to publish to an Azure Artifacts feed. select your feed from the dropdown menu.

Publish to a public registry

::: moniker range=">= azure-devops-2019"

To publish your packages to a public npm registry such as npmjs.com, you must first create a service connection to connect to the desired external service.

You can do this by going to your Project settings then selecting Service connections.

  1. Select Create service connection to create a new service connection.

    :::image type="content" source="./media/create-service-connection.png" alt-text="Screenshot showing how to create a new service connection":::

  2. Select npm then fill out the required fields. Select Save when you are done.

See Manage service connections to learn more about how to create, manage, secure, and use service connections.

To publish a package to an npm registry, add the following snippet to your yaml file.

- task: Npm@1
  inputs:
    command: publish
    publishRegistry: useExternalRegistry
    publishEndpoint: '<NAME_OF_YOUR_SERVICE_CONNECTION>'
  • publishEndpoint: required when publishRegistry == useExternalRegistry. Copy and paste the name of the service connection you created earlier.

::: moniker-end

::: moniker range="< azure-devops-2019" YAML is not supported in TFS. ::: moniker-end

Follow the steps below to publish your npm packages to a public npm registry using the classic pipeline.

  1. From within your pipeline, select the + sign to add a task to your pipeline, then search for the npm task. Select Add to add it to your pipeline.

    :::image type="content" source="./media/add-npm-task.png" alt-text="Screenshot showing how to find and add the npm task":::

  2. Fill out the required fields and make sure you select External npm registry to point to the public registry. Enter the name of your service connection in the External Registry field or create a new service connection if you haven't done so already.

    :::image type="content" source="./media/npm-publish-registry.png" alt-text="Screenshot showing how to configure the npm publish task to publish to public registries":::

  • Display name: name of your task.
  • Command: publish
  • Working folder that contains package.json: path to the folder containing the target package.json and .npmrc files. Leave this blank if those files are at the root of your repo.
  • Registry location: select External npm registry to publish to public registries such as npmjs.com. Enter the name of your service connection.

Related articles