How to resolve NPM packages from different organization(Azure Devops)

693 Views Asked by At

We have an NPM package say 'design' in say organization1, I have a pipeline which is part of the same organization that is able to resolve the package with just npmrc file. I wanted to access the packages 'design' from organization2, I am not able to read/resolve the package. pipeline throws 401.

  1. I tried setting up Service connection in Azure devops and try to use - same response
  2. tried with PAT directly on the npmrc file - same response
  3. From this blog, we have to set up all the properties, I tried - same response.

Is there I have to do something else to resolve the packages in external organization ?

latest .npmrc

@<reg>:registry=https://<reg>.pkgs.visualstudio.com/_packaging/<feed>/npm/registry/
//https://<reg>.pkgs.visualstudio.com/_packaging/<feed>/npm/registry/:_password=#{npm_PAT}#
//https://<reg>.pkgs.visualstudio.com/_packaging/<feed>/npm/registry/:username="notrequired"
//https://<reg>.pkgs.visualstudio.com/_packaging/<feed>/npm/registry/:email="[email protected]"
//https://<reg>.pkgs.visualstudio.com/_packaging/<feed>/npm/registry/:always-auth = true
1

There are 1 best solutions below

2
On BEST ANSWER

To resolve the packages in external organization, you can add the following content to .npmrc file:

Project feed:

; begin auth token
//orgname.pkgs.visualstudio.com/projectname/_packaging/456/npm/registry/:username=AzureTest23
//orgname.pkgs.visualstudio.com/projectname/_packaging/456/npm/registry/:_password=[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
//orgname.pkgs.visualstudio.com/projectname/_packaging/456/npm/registry/:email=npm requires email to be set but doesn't use the value
//orgname.pkgs.visualstudio.com/projectname/_packaging/456/npm/:username=AzureTest23
//orgname.pkgs.visualstudio.com/projectname/_packaging/456/npm/:_password=[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
//azuretest23.pkgs.visualstudio.com/projectname/_packaging/456/npm/:email=npm requires email to be set but doesn't use the value
; end auth token

Organization Feed:

; begin auth token
//orgname.pkgs.visualstudio.com/_packaging/234/npm/registry/:username=AzureTest23
//orgname.pkgs.visualstudio.com/_packaging/234/npm/registry/:_password=[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
//orgname.pkgs.visualstudio.com/_packaging/234/npm/registry/:email=npm requires email to be set but doesn't use the value
//orgname.pkgs.visualstudio.com/_packaging/234/npm/:username=AzureTest23
//orgname.pkgs.visualstudio.com/_packaging/234/npm/:_password=[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
//orgname.pkgs.visualstudio.com/_packaging/234/npm/:email=npm requires email to be set but doesn't use the value
; end auth token

Then you need to create a PAT with the Packaging Read and Write permission of the organization1.

enter image description here

Note: You need to convert the PAT to base64 type and replace the token value in .npmrc file.

To get the detailed settings, you can navigate to Azure Feed -> Connect to feed -> NPM -> Other and check the .npmrc file settings.

enter image description here

Update:

To convert the PAT to base64 type, we can follow this doc: Credentials setup