Using variables in appveyor.yml

niemand.richard's Avatar

niemand.richard

11 Dec, 2018 05:48 AM

Hi All

I am trying to get my head around building a .net core app (SDK 2.1) on AppVeyor, so far I have got 90% of the process bedded down, however I am struggling with publishing my package to NuGet - more specifically using variables in the appveyor.yml file, on this line:

after_build:
  - cmd: dotnet nuget push Rn.Common.1.0.{build}.nupkg -k {NuGetKey} -s https://www.nuget.org/

Ideally I would like it to substitute 2 variables here - (1) the build number to address the packaged NuGet file and (2) and environment variable I defined for the NuGet publish key. I have tried many different ways of escaping the variable and Googled the heck out of it with no luck.

Could someone please point me in the right direction here - it would be greatly appreciated.

P.S. presuming I get this right - would the API key be printed out in the build log?

e.g. https://ci.appveyor.com/project/rniemand/rn-common/builds/20917617

  1. Support Staff 1 Posted by Owen McDonnell on 11 Dec, 2018 07:09 AM

    Owen McDonnell's Avatar

    For cmd: environment variables are accessed by surrounding variable name with %%.
    i.e. %build%, %NuGetKey%

  2. 2 Posted by niemand.richard on 11 Dec, 2018 09:21 PM

    niemand.richard's Avatar

    Thanks for that - I replaced the line in question with:

        - cmd: dotnet nuget push Rn.Common.1.0.%version%.nupkg -k %NuGetKey% -s https://www.nuget.org/

    But it didn't seem to work:

    cd bin/Release
    dotnet nuget push Rn.Common.1.0.%version%.nupkg -k %NuGetKey% -s https://www.nuget.org/
    error: File does not exist (Rn.Common.1.0..nupkg).
    Command exited with code 1

  3. Support Staff 3 Posted by Owen McDonnell on 11 Dec, 2018 10:00 PM

    Owen McDonnell's Avatar

    Here's a list of environment variables set for every build. Version is not one of them, so unless you set it as an environment variable its not available. ...Perhaps you meant to use APPVEYOR_BUILD_VERSION.

  4. 4 Posted by niemand.richard on 11 Dec, 2018 10:43 PM

    niemand.richard's Avatar

    Thanks for that - I gave up on the venture because I was concerned of exposing my API key in the build log, and had a lot more success with a PowerShell script, namely:

    https://github.com/rniemand/Rn.Common/blob/master/appveyor.yml

    and

    https://github.com/rniemand/Rn.Common/blob/master/build/package.ps1

    Appreciate all the help!

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? 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