Azure Powershell Scripts

Need a clarification on the Azure Powershell script support. Where do the pre-deploy, deploy, and post-deploy scripts run and what do they have access to? E.g. do they run on the Azure service node? Do they run on the Octopus server? Can they manipulate web applications or do they only have access to the Azure packages?

My intent is to transform the web.config for a Web Role at deploy time. I have a quick powershell script that can perform the transform but it needs access to the web config to do this.

Hi Adam,

They run on the Octopus Server (we can’t remotely run them in Azure), and they’ll only have access to the .cscfg and cspkg file (and anything else in your NuGet package). If you need to open up the .cspkg file and modify the contents, you can do this in your PreDeploy.ps1 script, but we don’t have any tooling to make it easy to open or save the package file. That said, they are just ZIP files so you might be able to put something together.

Hope that helps,

Paul

I was able to get this working after fighting Azure packaging formats as well as cspack. For others looking to do this see the steps below.

1 - Create powershell commandlet for transforming config files. You can use Microsoft.Web.XmlTransform for this.
2 - Install Azure command line tools on your Octopus server and add them to your system path.
3 - Package your web application similar to the following
@@@









@@@
2 - Write PreDeploy.ps1 similar to the following
@@@
Import-Module .\tools\packager\ProjectName.Web.WebRolePackager.dll
Write-Host "Transforming .\content\Web.Config using Web.$OctopusEnvironmentName.config"
Transform-File -SourceFile .\content\Web.Config -TransformFile .\content\Web.$OctopusEnvironmentName.config
$content_path = Resolve-Path .\content
$content_path = $content_path.ToString().ToLower()
& ‘cspack’ “ServiceDefinition.csdef” “/out:ProjectName.Web.WebRole.cspkg” “/role:ProjectName.Web;content” “/sites:ProjectName.Web;Web;$content_path”
@@@