Skip to content

Instantly share code, notes, and snippets.

@cristobal
Created April 11, 2021 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristobal/73ac9ebefec3f652d9a5d35737011134 to your computer and use it in GitHub Desktop.
Save cristobal/73ac9ebefec3f652d9a5d35737011134 to your computer and use it in GitHub Desktop.
Setting custom NPM_USER_CONFIG with readonly NPM_TOKEN via Powershell (Tested in TeamCity)
# Write NPM_TOKEN registry without BOM @see https://stackoverflow.com/a/32951824
[IO.File]::WriteAllLines("$(Get-Location)\.npmrc", "//registry.npmjs.org/:_authToken=$env:NPM_TOKEN")
# Set Custom NPM_CONFIG_USERCONFIG Environment variable
$env:NPM_CONFIG_USERCONFIG="$(Get-Location)\.npmrc"
# debug who you are
# npm whoami
# replace * with the npm script you want to run.
npm run *
# Remove Custom NPM_CONFIG_USERCONFIG Environment variable
Remove-Item Env:NPM_CONFIG_USERCONFIG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment