Octopus 3.1 beta - update Cloud Service Definition file


This is a similar question to those asked before about updating the *.CSDEF file, but none of those threads have been able to help as they don’t really provide full examples.

I have a cloud service package file created by MSDEPLOY. This correctly unpacked by Octopus Deploy 3.1 and configuration transforms applied to the *.CSCFG file. Unfortunately I need to udpate the *CSDEF file. This appears to be in the \ServiceDefinition folder but the file appears to have be already parsed by the msdeploy step. I want to change content such as VM Size but this has been removed. Odd, I know.

The source is this:

The result in the unpacked file is this:

i.e, the vmsize has been removed :frowning:

The other posts talk about running a PreDeploy.ps1 script, which I have done to edit other content on the *.CSCFG file, but I really don’t know what to do about this… where has this value gone??

Can I change this some other way in Octopus?


Unfortunately I don’t think there’s any way to change these values from Octopus.

I’m not sure if it is do-able, but are you able to set up multiple .csdef files and create different .cspkg’s depending on an MSBuild flag? Then perhaps you could deploy different packages depending on the environment in Octopus.


Hi, I got to the bottom of this

(NB: Accidentally made this private - can you set it to public?)

The initial ServiceDefinition file is automatically “cleaned” up when originally built. The VMSize parameter was, in my case, set to “small”. This is default value so this is “helpfully” removed by the package process in MSDEPLOY.

Using PowerShell, I re-added the value in the PreDeploy.ps1, and set this to a value from Octopus… bingo…

Powershell example below:

write-host “Starting Service Definition rewrite”

#Default to current location and then subdirectory ("#{Octopus.Action.Azure.PackageExtractionPath}" doesn't seem to work correctly
$def = "ServiceDefinition\ServiceDefinition.csdef"

$csdeffile = Get-Item $def
[xml]$csdefcontent = get-content $csdeffile

#Find the webrole we want in a multi-webrole cloud service. Assume this exists
$webrole = $csdefcontent.ServiceDefinition.WebRole | where {$_.name -eq NNNNNN}

##Update the vmsize. Add if not available

#Save the changes

write-host "Service Definition rewrite successful"

Thank you for this example. Would you mind expanding on it a little? Specifically, after the MSBUILD step, how do you extract the csdef file from the csdx file in the cspkg? And then after you re-write it using the script above, how do you put it back together in the csdx file?


Update: Combined the information from http://docs.octopusdeploy.com/display/OD/Deploying+a+package+to+an+Azure+Cloud+Service and this post to implement the csdef transform. Couple of items to note:

  1. Set Octopus.Action.Azure.LogExtractedCspkg to true and check the task log in Verbose mode. You’ll see that Octopus extracts the cspkg file and further extracts all the archives within the cspkg. You see the whole directory structure.
  2. I then used the PreDeploy script as above to modify the csdef based on target deploy. The only isssue I ran into was that variable substitution was not being made (for instance #{vmsize}. I had to use $OctopusParameters[‘vmsize’] instead.
  3. The cscfg file is changed via variable substitutions. Also any web.config or app.config in the containing roles are also transformed if the target web.xxx.config / app.xxx.config is there. It was great to see Octopus apply those for me as expected.