Deployment Agent and Environment Variables

Scott Vaughan's Avatar

Scott Vaughan

02 Nov, 2018 09:13 AM

I am using the deployment agent on my remote server to deploy a .net console application.

I have followed the instructions from https://www.appveyor.com/docs/deployment/agent/#overriding-settings... and have succesfully deployed the application to the server. I have set the connection string for the application in the 'Environment variables' section user 'Settings'.

The problem is that no Environment variables is written to the server when the application is deployed. I am looking in 'System Properties' - 'Environment Variables' in a windows environment.

  1. 1 Posted by Ilya Finkelshte... on 02 Nov, 2018 10:20 PM

    Ilya Finkelshteyn's Avatar

    Hi Scott,

    Those variable can be used by AppVeyor during deployment time, and they are specific to deployment Agent session. They are not being set as a system-wide environment variables.

    You can use custom before- or after- deployment scripts (should be in the root of artifact package) to set those variables as you need. Those scripts run during deployment and have access to variables you set up on Environment UI (or send from the build)

    So in that script you can do this to make it system wide:

    setx myVariable $env:myVariable /M
    

    This should happen before your console application start (to ensure app pick up new system variable). So before-deploy.ps1 is a better candidate.

    Also I would consider to simple write this connection string to the registry.

    Let us know if this works for you.

    Ilya.

  2. 2 Posted by Scott Vaughan on 05 Nov, 2018 09:26 AM

    Scott Vaughan's Avatar

    Thanks for your reply. I am still having some trouble understanding what the Environment Variables section is for within the Appveyor deployment settings page.

    I need a different set of values for each agent. Currently I have UAT and PRODUCTION environments which will need different environment variable values for each.

    If the Appveyor agent is unable to set these values per environment I may have to use another deployment service.

  3. 3 Posted by Ilya Finkelshte... on 05 Nov, 2018 10:03 AM

    Ilya Finkelshteyn's Avatar

    Environment variables are used to substitute values for deployment settings during deployment time, as described in this part of documentation. In this example site_name can be send from the build, and Environment section provides default value (in case no value has been sent from the build).

    Those environment variables are not being set as system environment variables on the computer where agent is installed (as you probably expect). However they are available to before- and after- deployment scripts and you can use those scripts to update system environment variables on the computer where agent is installed.

    As proposed in previous message, you can create before-deploy.ps1 file, with setx myVariable $env:myVariable /M content, and place it in the root of your artifact zip folder. When agent unzips the artifact and sees this file, it will be executed and system variable you need will be set. I assume you set up myVariable with proper value in agent environment settings.

  4. 4 Posted by Scott Vaughan on 05 Nov, 2018 11:03 AM

    Scott Vaughan's Avatar

    I think I have sorted it now thanks. I have added the script in my before-deploy.ps1 script.

    Thanks for your help.

  5. 5 Posted by Ilya Finkelshte... on 05 Nov, 2018 04:10 PM

    Ilya Finkelshteyn's Avatar

    Great, thank for the update. Feel free to ping us when needed!

  6. Ilya Finkelshteyn closed this discussion on 05 Nov, 2018 04:10 PM.

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

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

 

26 Sep, 2024 03:49 PM
26 Sep, 2024 09:02 AM
25 Sep, 2024 07:07 PM
24 Sep, 2024 08:39 PM
24 Sep, 2024 06:47 AM
20 Sep, 2024 05:50 PM