Deploying using PowerShell Desired State Configuration in Release Management
With Microsoft Release Management 2013 Update 3 RC, you can now use Windows PowerShell or Windows PowerShell Desired State Configuration (DSC) for deploying and managing configuration data.
Windows PowerShell (PS)
Refer to Scripting with Windows PowerShell (PS) for more details. These scripts can be same as what you might have been already using to deploy using Microsoft Deployment Agent.
RM 2013 Update 3 “Deploy using PowerShell” requires PS version on the target servers to be of version 4.0 or higher.
Windows PowerShell Desired State Configuration (DSC)
DSC is a PowerShell extension and ships with Windows Server 2012 R2 and Windows 8.1. DSC is also part of Windows Management Framework 4.0 which ships as an optional update and can be installed to Windows Server 2012, Windows Server 2008R2, Windows 7 and Windows 8.
The PowerShell v4 DSC extension adds a new keyword called “Configuration”. With this keyword, which is actually a “function”, you define a DSC configuration block. RM leverages Windows DSC Local Configuration Management Engine to apply the configuration when a PowerShell script has “DSC Configuration” block in it.
Deployments using PS/DSC in Release Management
“PSScriptPath” action parameter
Specify the relative path to the PS/DSC script file with respect to the package path (Component).
“PSConfigurationPath” action parameter
Specify the relative path to the PS/DSC script initialization file with respect to the package path (Component). This is an optional parameter, when set, RM will run this PS script prior invoking the main-script file.
In RM, you can define configuration data separately from the logic of your configuration in a PS script file and use it to initialize the main script (Here main-script is the actual PS/DSC script referred by ‘PSScriptPath’).
Variables initialized here will be visible to the main script file. By using initialization script, you can potentially –
- Initialize environment specific variables
- Configure LCM setting
- Install custom Modules
Initialization PS script file has following advantages:
- It allows you to reuse your configuration data for different resources, nodes, and configurations.
- Configuration logic is more reusable if it does not contain hard-coded data. This is similar to good scripting guidelines for functions.
- If some of the data needs to change, you can make the changes in one location, thereby saving time and reducing errors.
Initialize environment specific variables
a) Look at the below sample which shows how you can parameterize your main DSC script using this initialization script file.
Sample PS DSC script file
Initialization PS Script file
- $ConfigData is initialized using PS script file specified in ‘PSConfigurationPath’
- Ensure that you don’t specify “–OutputPath” parameter for the MOF file. RM handles the MOF file generated and its cleanup.
- You don’t need to call Start-DscConfiguration as you might’ve noticed. RM applies the cmdlet as part of the DSC execution
Configure LCM settings
Initialization script file can also be used to configure the LCM (Local Configuration Manager engine) of the target node.
- RM doesn’t apply ‘Set-DscLocalConfigurationManager’, needs to be set explicitly as shown in the sample above
- Cleanup of ‘Meta MOF’ file has to be handled outside of RM
Install custom modules
Initialization script to install custom modules
- Drop the custom module along with build. For e.g. custom modules are packaged under “CustomModules” folder in the build
- Copy custom modules using Initialization script
“$applicationPath” variable points to the root folder path of the build that has been copied locally onto the target node by RM.
Consider this scenario: As part of your deployment if you intend to copy build to a folder on target machine say c: DeploymentFolder or D: DeploymentFolder
DSC script file (main-script)
- “$applicationPath”will always point to root directory of your build which you are deploying
- Here we have used a DSC File resource to copy the folders recursively. As the source path refers to “$applicationPath”