When preparing a DSC script for deploying an application using Release Management it is often handy to test and debug that script locally. Nobody writes code that works the first time, right? However, you’ll quickly run into the fact that Release Management does some things slightly different than “vanilla” DSC (for example: .psd1 is not .ps1) and also provides some extra’s, like the $ApplicationPath variable that holds the path to the bits you’re deploying and the configuration of WinRM. Because of this, I found myself using the following workflow:
- Write DSC script
- Test and debug locally
- Configure Release Management with this DSC script
- Test and debug deployment from Release Management
- Change DSC script to work from Release Management
I wanted to eliminate step #5 and seriously reduce the time needed for #4.
For that purpose, I have created a PowerShell wrapper script. This script takes the same input parameters that you would configure in Release Management and executes your DSC script for you, much in the same way as Release Management would. This means you can test and debug your DSC scripts locally (without using Release Management) and when you eventually configure them in Release Management you don’t have to change anything!
You can download the script from my GitHub: Deploy_RM_local.ps1. Here’s how it works.
In Release Management, you use a “Deploy Using PS/DSC” block for deploying using DSC:
The interesting variables here are:
- PSScriptPath: the path to your DSC script. This path is relative to the location of the component you’re deploying (usually the folder from your TFS drop).
- PSConfigurationPath: the path to the script that contains your configuration data. Again, this is a relative path.
Furthermore, Release Management will provide a variable $ApplicationPath that will contain the absolute path to the folder where Release Management will have copied your component. We’ll need these three variables.
- Download the bits that you want to deploy to the server you want to test on, e.g. to “C:\Deploy\SampleApp_20150527.3”.
- Make sure you have the “Deploy_RM_local.ps1” somewhere on the server, e.g. in “C:\Scripts”
- Open a PowerShell prompt and navigate to the folder containing the script:
- Execute the “Deploy_RM_local.ps1” script, feeding it the three paths as input. Optionally, you can add the “-Verbose” parameter to get some more logging. For example:
.\Deploy_RM_local.ps1 -ApplicationPath "C:\Deploy\SampleApp_20150527.3" -PSConfigurationPath "Deploy\DeployConfig_AzureD.ps1" -PSScriptPath "Deploy\Deploy.ps1" -Verbose
That’s it! Happy deploying!