1

I am looking for a way to remove the need to write the Azure DevOps npm artifactory npm token to a file. In the docs they provide for non Windows environment, they say we should add this content to our .npmrc.

registry=https://pkgs.dev.azure.com/<org>/<project>/_packaging/<registry>/npm/registry/

always-auth=true

; begin auth token
//pkgs.dev.azure.com/<org>/<project>/_packaging/<registry>/npm/registry/:username=<org>
//pkgs.dev.azure.com/<org>/<project>/_packaging/<registry>/npm/registry/:_password=[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
//pkgs.dev.azure.com/<org>/<project>/_packaging/<registry>/npm/registry/:email=npm requires email to be set but doesn't use the value
//pkgs.dev.azure.com/<org>/<project>/_packaging/<registry>/npm/:username=<org>
//pkgs.dev.azure.com/<org>/<project>/_packaging/<registry>/npm/:_password=[BASE64_ENCODED_PERSONAL_ACCESS_TOKEN]
//pkgs.dev.azure.com/<org>/<project>/_packaging/<registry>/npm/:email=npm requires email to be set but doesn't use the value
; end auth token

However, I would like to use environment variables for this if it's possible somehow.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
The Fool
  • 16,715
  • 5
  • 52
  • 86

1 Answers1

0

The format of these code is fixed. You could to set your PAT(Personal access token) in the environment variables.

Please add the environment variable to your .bashrc or other startup shell file.

export TOKEN=your PAT

Then use it in .npmrc file with ${TOKEN}.

//pkgs.dev.azure.com/<org>/<project>/_packaging/<registry>/npm/registry/:_password=${TOKEN}

Similar issues here:

.npmrc config file not reading environment variable to download private Node module

How to set env var for .npmrc use

unknown
  • 6,778
  • 1
  • 5
  • 14