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. 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. 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. 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. 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.

  8. Ilya Finkelshteyn closed this discussion on 14 Oct, 2019 09:01 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

Recent Discussions

13 Dec, 2019 05:26 PM
13 Dec, 2019 11:28 AM
12 Dec, 2019 09:36 PM
12 Dec, 2019 09:25 PM
12 Dec, 2019 06:01 PM


11 Dec, 2019 11:29 PM
11 Dec, 2019 08:47 PM
11 Dec, 2019 01:39 PM
10 Dec, 2019 12:29 AM
09 Dec, 2019 05:35 AM
07 Dec, 2019 04:20 PM