.NPRC file environment variable from Appveyor UI

vijay.malhi's Avatar


14 Jun, 2023 11:08 AM


I am using a .nprc file for the Luna component. I am setting GitHub token values as an environment variable and setting these values in the appveyor.yml file and accessing these values from UI. But it throws below error please help me out.

 ERR! 401 Unauthorized - GET https://npm.pkg.github.com/download - unauthenticated: User cannot be authenticated with the token

.NPRC file content

Appveyor.yml file
- cmd: |
    NuGet restore DeliveryHubDeploy.sln
    set GITHUB_TOKEN = %Luna_GitHub_Token%

%Luna_GitHub_Token% This value I stored in Appveyor UI in the environment variable

  1. Support Staff 1 Posted by Feodor Fitsner on 14 Jun, 2023 01:56 PM

    Feodor Fitsner's Avatar

    Try updating .npmrc contents with an actual token:

    - echo //npm.pkg.github.com/:_authToken=%Luna_GitHub_Token% > .npmrc

    Also, when setting variable on AppVeyor UI make sure: a) "lock" icon is on to mark variable as secure, b) variable value is pasted as plain text, without prior encrypting with "Encrypt YAML" tool, c) you are not testing that in PR as by default secure variables are not set in PR builds. Hope that helps.

  2. 2 Posted by vijay.malhi on 15 Jun, 2023 04:06 PM

    vijay.malhi's Avatar

    Hi Fedor,

    Thank you for your response to the above. I tried what you said still getting the same issue. Maybe I am missing anything. I have added the actual token key name in the NPRC file which is attached you can see.

    Do I need to change anything in the AppVeyor.yml file?

    Please help me with this.

  3. Support Staff 3 Posted by Feodor Fitsner on 19 Jun, 2023 01:49 PM

    Feodor Fitsner's Avatar

    It's not the same. %Luna_GitHub_Token% won't be automatically replaced inside .npmrc for you.

    What I meant is writing a real token value to to .npmrc file, not an env variable name.

    When you do this %Luna_GitHub_Token% is replaced with variable value by echo command and overwrites the contents of .npmrc:

    - echo //npm.pkg.github.com/:_authToken=%Luna_GitHub_Token% > .npmrc
  4. Feodor Fitsner closed this discussion on 19 Aug, 2023 09:03 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac