title | ms.custom | description | ms.assetid | ms.topic | ms.date | monikerRange | recommendations |
---|---|---|---|---|---|---|---|
Publish npm packages with Azure Pipelines |
devx-track-js |
Learn how to publish npm packages to internal and external feed using Azure Pipelines. |
F4C61B91-2C5B-4848-A4BF-B658F549673A |
conceptual |
11/14/2024 |
<= azure-devops |
true |
[!INCLUDE version-lt-eq-azure-devops]
With Azure Pipelines, you can publish your npm packages to Azure Artifacts feeds within your organization and in other organizations. This article will guide you through publishing your npm packages to internal and external feeds using YAML and Classic pipelines.
-
Create an Azure DevOps organization and a project if you haven't already.
-
Create a new feed if you don't have one already.
-
If you're using a self-hosted agent, make sure that it has Node.js and npm.
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.
steps:
- task: NodeTool@0
inputs:
checkLatest: true
- task: npmAuthenticate@0
displayName: 'Authenticate to Azure Artifacts feed'
inputs:
workingFile: .npmrc
- script: |
npm publish
displayName: Publish
::: moniker range="azure-devops"
- Sign in to your Azure DevOps organization, and then navigate to your project.
::: moniker-end
::: moniker range="< azure-devops"
- Sign in to your Azure DevOps collection, and then navigate to your project.
::: moniker-end
::: moniker range="<=azure-devops"
- Select Pipelines, and then select your pipeline definition.
::: moniker-end
-
Select Edit, and then select the
+
sign to add a new task. Add the Node.js tool installer, npm Authenticate and Command line tasks to your pipeline definition. You can leave the Node.js tool installer task with the default settings and configure the npm Authenticate and Command line tasks as follows:-
npm Authenticate task: Select the path to the .npmrc file.
-
Command line task:
- Display name: Publish.
- Script:
npm publish
-
To publish your packages to a feed in another Azure DevOps organization, you must first create a personal access token in the target organization.
Navigate to the organization hosting your target feed and Create a personal access token with Packaging > Read & write scope. Copy your personal access token as you'll need it in the following section.
-
Sign in to the Azure DevOps organization where your pipeline will run, and then navigate to your project.
-
Navigate to your Project settings > Service connections.
-
Select New service connection, select npm, and then select Next.
-
Select Username and Password as the Authentication method, and then enter your Registry URL. Enter your Username (a placeholder, as Azure Pipelines will use your
.npmrc
configuration file and the personal access token you created earlier to authenticate). For Password, paste your personal access token. Provide a name for your service connection, and check the Grant access permission to all pipelines checkbox. -
Select Save when you're done.
-
Sign in to your Azure DevOps organization, and then navigate to your project.
-
Select Pipelines, and then select your pipeline definition.
-
Select Edit, and then add the following snippet to your YAML pipeline.
- task: NodeTool@0 inputs: checkLatest: true - task: npmAuthenticate@0 displayName: 'Authenticate to Azure Artifacts feed' inputs: workingFile: .npmrc customEndpoint: <SERVICE_CONNECTION_NAME> - script: | npm publish displayName: Publish
::: moniker range="azure-devops"
- Sign in to your Azure DevOps organization, and then navigate to your project.
::: moniker-end
::: moniker range="< azure-devops"
- Sign in to your Azure DevOps collection, and then navigate to your project.
::: moniker-end
::: moniker range="<=azure-devops"
- Select Pipelines, and then select your pipeline definition.
::: moniker-end
-
Select Edit, and then select the
+
sign to add a new task. Add the Node.js tool installer, npm Authenticate and Command line tasks to your pipeline definition. You can leave the Node.js tool installer task with the default settings and configure the npm Authenticate and Command line tasks as follows:.-
npm Authenticate task:
- Select the path to your .npmrc file.
- Select the service connection you created earlier from the Credentials for registries outside this organization/collection dropdown menu.
-
Command line task:
- Display name: Publish.
- Script:
npm publish
-