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 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.
Prerequisites
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.
Publish packages to a feed in the same organization
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
Publish packages to a feed in another organization
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.
Create a service connection
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.
Publish packages
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