I recently improved all of my powershell scripts for RM2015 vNext deployments by including a param() clause at the start of each script. Only to discover that when using PS/DSC actions in RM2015 (and 2013 for that matter) you cannot pass parameters! Quite frustrating as the main reason i did this improvement was because of Microsoft’s message at the end of their Release Management vNext Plans blog post
To maximize the chances of carrying your investments forward, we recommend that you write PS scripts to drive your deployments with the current versions of RM server
and the default/recommended way to work with powershell scripts using the PowerShell on Target Machines VSO agent task is to pass parameters. Sure, the VSO agent task has the advanced option “Sessions Variables” for backward compatability but I would really prefer to make my RM2015 solution forward compatible instead.
So how do I make my RM2015 scripts and release templates forward compatible? Turns out it is not that difficult to achieve. You’ll need a generic wrapper script and three variables in RM. Your wrapper script should look like this:
Invoke-Expression "$PSScriptRoot\$PowerShellScript $ScriptArguments"
Make sure your wrapper script is included in your build drop together with your other deployment scripts. Then add three global variables in RM2015.
- PSScriptPath – set the value to the “drop releative” path of your wrapper script. (If this path differ between components make this a component variable instead)
- PowerShellScript – do not set a value at the global level, we just want the variable to show up in the dropdown list for Custom configuration in our PS/DSC action.
- ScriptArguments – do no set a value at the global level, same reason.
And now, your PS/DSC actions can look like this:
which corresponds nicely with how it is done in the VSO agent task:
We are now forward compatible!
One thought on “Calling scripts in RM2015 vNext style”
I found the same issue. I’ve submitted a case to Microsoft for this same thing.
Comments are closed.