Save environment variables after build and set them again when deploying that specific build

jeremiah's Avatar


24 Jul, 2019 08:30 PM

This would be a helpful feature so manual deployments work as well as automated deployments. The build process sets some important environment variables that normally carry over to the deploy process. Currently I cannot use manual deploy with an AppVeyor Agent unless I set the proper variables on the environment settings page. Some of these variables include $env:APPLICATION_SITE_NAME which is set with $env:website_name in the appveyor.yml file. Another variable named website_env varies between builds and becomes part of the web address making it critical for proper deployment.

  1. Support Staff 1 Posted by Owen McDonnell on 26 Jul, 2019 10:17 PM

    Owen McDonnell's Avatar

    Sorry for the delay in getting back to you. We were running a few workaround experiments.
    Can you share some more details about your deployment approach. Do you deploy different builds from the same project or are different projects using the same deployment environment? Also, to what kind of server are you deploying?

  2. 2 Posted by jeremiah on 26 Jul, 2019 10:58 PM

    jeremiah's Avatar

    We have multiple projects deploying to the same environment, which is a Windows 2012 server running IIS for internal testing. When deployment has failed due to problems on the server, or perhaps it succeeded and we have since made changes on the server and we want to try it again, we'd like an easy way to redo the deployment exactly as it was done the first time.

    Basically saving all the environment variables that exist after a build and setting them again on deploy would solve the problem. Each specific build would have it's own set of saved environment variables. The deploy process could read these from a file or database and set them before starting the deployment.

  3. Support Staff 3 Posted by Owen McDonnell on 29 Jul, 2019 02:54 PM

    Owen McDonnell's Avatar

    I see.
    What you could do is set something like the following in the install: stage of your build,

    - ps: >-
        $env:var1 = 'val1'
        $env:var2 = 'val2'
        $vars = @{
          "var1" = $env:var1
          "var2" = $env:var2
        $vars  | ConvertTo-Json | Set-Content .\vars.json

    and then, make sure you specify that artifact.

      - path: vars.json

    And finally, include a before-deploy.ps1 file in your zipped project artifact with something like the following...

    $projectName = $env:APPVEYOR_PROJECT_NAME
    $appName = $env:APPLICATION_NAME
    $vars = Get-Content "C:\appveyor\projects\$projectName\applications\$appName\vars.json" | ConvertFrom-Json
    [Environment]::SetEnvironmentVariable("var1", "$vars.var1", "Machine")
    [Environment]::SetEnvironmentVariable("var2", "$vars.var2", "Machine")

    Does it make sense?

  4. 4 Posted by jeremiah on 29 Jul, 2019 05:54 PM

    jeremiah's Avatar

    That makes sense, but what about variables set in the AppVeyor Agent settings such as deploy_website and hostname? We set these dynamically with environment variables such as $(websitezip_hostname). I think the environment variables need to be set before the deployment agent starts running?

  5. Support Staff 5 Posted by Owen McDonnell on 29 Jul, 2019 09:36 PM

    Owen McDonnell's Avatar

    Sure, if you need them to be set on the target server, you can put them in the file as well, otherwise they are used for deployment purposes only.

  6. 6 Posted by jeremiah on 12 Aug, 2019 09:55 PM

    jeremiah's Avatar

    I think we are talking about different things. I want to save the AppVeyor agent deployment settings that were set at build time as seen above, which uses evaluations like $(websitezip_site_name) to set "site_name". Is there any way to save the appveyor agent settings that were set for that particular build and reuse them if a manual deploy is performed?

  7. Support Staff 7 Posted by Owen McDonnell on 14 Aug, 2019 06:20 PM

    Owen McDonnell's Avatar

    I'm not sure if you specifically mean the web UI by manual deploy, but you could use the json file as a basis for scripting an api call which passes along those variables.

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


? 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