-
Notifications
You must be signed in to change notification settings - Fork 4
Configuring
Applications will often require different configuration depending on where they are being deployed.
##Specifying Variables##
appsettings / connection strings / scripts how to use in scripts...
Passing in
Install-DeploymentPackage and Invoke-Powerdeploy each have a parameter to supply variables to a deployed application. The Variable parameter takes a hash table of name value pairs representing the variables for the deployment.
As an example, consider an application configuration file for your application that is deployed with the application:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="debuglevel" value="WARN" />
<add key="databaseinstance" value="development" />
</appSettings>
</configuration>You can configure the application settings values at deployment time by passing them in when installing the package (or invoking a remote deployment):
Install-DeploymentPackage `
-PackageArchive SamplePackage_1.2.3.zip `
-Environment Integration `
-Variable @{ 'debuglevel' = 'ERROR'; 'databaseinstance' = 'integration' }When Powerdeploy installs the package, it will automatically replace the values in the application configuration file with the values supplied on the command line.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="debuglevel" value="ERROR" />
<add key="databaseinstance" value="integration" />
</appSettings>
</configuration>##Managing Variables## Supplying configuration variables as a parameter at deployment time offers great flexibility for varying configuration and testing deployments, but it doesn't promote repeatability of deployments or visibility of the configuration applicable at a point in time.
Ideally, configuration variables would be versioned, like source code, and auditable.
Powerdeploy does not force the use of any specific configuration management solution and is perfectly content to take the variables hash table from any source. You could (and should) wrap Powerdeploy in a script that pulls variables from a repository for a given application version, going to a specific environment and then pass those in on the command line. The repository could be a SQL database, a web service, a filesystem, or any other conceivable store that could return name-value pairs based on some deployment criteria.

This approach is common with Powerdeploy, so an example wrapper script is included with Powerdeploy that can be used as-is or tweaked as needed. DeployPackage.ps1 (in the Examples folder) is a simple script which takes many of the parameters required by Invoke-Powerdeploy, retrieves configuration variables, and invokes Powerdeploy with the variables.
Although you can roll your own, Powerdeploy includes support for a simple filesystem based configuration repository. Once your configuration is made available, you can use Get-ConfigurationVariable to retrieve the applicable configuration.
Get-ConfigurationVariable `
-SettingsPath c:\mysettings.store `
-ApplicationName MyWebsite `
-Version 1.0.0 `
-EnvironmentName Integration `
-ComputerName testserver/viewing configuration variables (filtered)/
Passed in vs. retrieved
Storage
Scope & Precedence