NuGetApiKey Not Set

dustin+appveyor's Avatar


18 Mar, 2019 05:59 PM


I am a n00b when it comes to CI/CD, and I'm working on my first project and having trouble publishing my PowerShell module to the PowerShell Gallery via AppVeyor.

From what I have been able to determine, the issue is the $env:NuGetApiKey variable isn't being set via the secure variable.

I have a thread on reddit but thus far no one has been able to assist:

Here is a link to my Github project:
Here is a link to the latest build results:

I realize I could set this variable via the Environment section in the UI, but I would prefer to keep everything together to eventually use as a template if/when I start using more projects through AppVeyor.

Any assistance would be greatly appreciated!

Thank you,

  1. 1 Posted by Owen McDonnell on 18 Mar, 2019 10:33 PM

    Owen McDonnell's Avatar

    I'm guessing you may have started with some UI configuration and then switched to appveyor.yml and in the UI you don't have this variable set?
    Seems your config file is not being respected because of its casing. Can you switch to all lowercase appveyor.yml and try running the build

  2. 2 Posted by dustin+appveyor on 19 Mar, 2019 12:35 PM

    dustin+appveyor's Avatar

    You are correct! I did not set the variable via the UI. I lowercased the file and that did seem to change something: namely it broke the build as I had the script called wrong in my YML file. Fixed that but the build is still throwing the NuGetApiKey error.

    (I had no idea the file name was case sensitive, thanks for that!)

  3. 3 Posted by Owen McDonnell on 19 Mar, 2019 02:13 PM

    Owen McDonnell's Avatar

    Again i'm guessing, but maybe here you should change this line from

    ApiKey = $ENV:NuGetApiKey


    NuGetApiKey = $ENV:NuGetApiKey
  4. 4 Posted by dustin+appveyor on 19 Mar, 2019 02:39 PM

    dustin+appveyor's Avatar

    Thanks! But per the PSDeploy docs, that should be ApiKey.

    For the hell of it, I gave that a try: WithOption 'NuGetApiKey' is not a valid parameter for 'PSGalleryModule'

    I believe the issue is still on my AppVeyor configuration as I did the dumb and purposefully wrote out Write-Host $env:NuGetApiKey and the output was blank during a build, other variables show up just fine it seems.

  5. 5 Posted by dustin+appveyor on 19 Mar, 2019 02:50 PM

    dustin+appveyor's Avatar

    Just to confirm everything actually works elsewhere, I went into the settings on AppVeyor UI for the build ( and set the NuGetApiKey env variable to the unsecure string. Pushed a build and it published properly. This takes me back to believe I'm doing something wrong in my config or the yml file itself.

  6. 6 Posted by Owen McDonnell on 19 Mar, 2019 06:03 PM

    Owen McDonnell's Avatar

    Indeed it seems you are following the proper apikey naming.

    Everything looks ok in your appveyor.yml. It really seems like the decryption is just not happening properly
    . Can you try encrypting a test variable and then print it out from the psake script as i did in this build of a fork of your project.

  7. 7 Posted by dustin+appveyor on 20 Mar, 2019 02:30 PM

    dustin+appveyor's Avatar

    Huh, blank for me.

    I have in my project settings in the UI under Environment, Build Worker System is set to WMF 5. Is this overriding all the settings from my YML file? I just tried to delete that (which resets it back to VS 2015 in the UI) and tried to rebuild, no change. Foo is still blank.

  8. 8 Posted by Owen McDonnell on 20 Mar, 2019 02:59 PM

    Owen McDonnell's Avatar

    It's the other way around. Presence of yaml config file in repo overrides settings from UI, except for certain settings. You can read more details here.

    In the build you linked to I don't see the test variable declared in appveyor.yml. Did you set it in the UI?

  9. 9 Posted by dustin+appveyor on 20 Mar, 2019 03:18 PM

    dustin+appveyor's Avatar

    Oh right, sorry I got mixed up here!

    I linked to the wrong build sorry about that!

    It did work in the end, I basically used the UI to create the YAML file and the used export YAML to build my .yml file. The foo variable then was output properly.

    I moved my changes back to my master branch, updated the exported YML and removed or turned off all settings in the UI (just to be safe) and pushed a build through. Everything appears to be working great now!

    Not really sure what I did differently that caused it but perhaps it was me using OS: WMF instead of image?

    Thank you for your help! :)

  10. 10 Posted by Owen McDonnell on 20 Mar, 2019 08:55 PM

    Owen McDonnell's Avatar

    No problem. Yeah, it's best to stick to one configuration method, although environment variables set in the UI should get merged with those in the configuration file.

  11. Owen McDonnell closed this discussion on 20 Mar, 2019 08:55 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