Επεξεργασία

Κοινή χρήση μέσω


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

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

  1. Sign in to the Azure DevOps organization where your pipeline will run, and then navigate to your project.

  2. Navigate to your Project settings > Service connections.

  3. Select New service connection, select npm, and then select Next.

  4. 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.

  5. Select Save when you're done.

Publish packages

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

  2. Select Pipelines, and then select your pipeline definition.

  3. 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