Skip to content

Instantly share code, notes, and snippets.

@edwinf
Created January 22, 2015 15:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwinf/bb62a5884ac61e35b38c to your computer and use it in GitHub Desktop.
Save edwinf/bb62a5884ac61e35b38c to your computer and use it in GitHub Desktop.
Pre-Deployment script to change additional settings in the cscfg file for Octopus Cloud Service deployments.
$subnetName = $OctopusParameters["Azure Subnet Name"]
$virtualNetworkName = $OctopusParameters["Azure Virtual Network Name"]
$sslCert = $OctopusParameters["Azure SSLCertificate Thumbprint"]
$caCert = $OctopusParameters["Azure CACertificate Thumbprint"]
$vmName = $OctopusParameters["Azure Vm Name"]
$pathToCSCFG = [System.IO.Path]::Combine($OctopusOriginalPackageDirectoryPath, "ServiceConfiguration.Cloud.cscfg")
$xml = [xml](Get-Content $pathToCSCFG)
if (![string]::IsNullOrEmpty($virtualNetworkName)){
Write-Host "Virtuan Network Name is: $virtualNetworkName"
$xml.ServiceConfiguration.NetworkConfiguration.VirtualNetworkSite.name = $virtualNetworkName
}else{
Write-Host "'Azure Virtual Network Name' not set, skipping"
}
if (![string]::IsNullOrEmpty($subnetName)){
Write-Host "Subnet Name is : $subnetName"
$xml.ServiceConfiguration.NetworkConfiguration.AddressAssignments.InstanceAddress.Subnets.Subnet.name = $subnetName
}else{
Write-Host "'Azure Subnet Name' not set, skipping"
}
if (![string]::IsNullOrEmpty($vmName)){
Write-Host "VM Name is: $vmName"
$xml.ServiceConfiguration.Role.vmName = $vmName
}else{
Write-Host "'Azure Vm Name' not set, skipping"
}
if (![string]::IsNullOrEmpty($sslCert)){
foreach($node in @($xml.ServiceConfiguration.Role.Certificates.Certificate)){
if ($node.name -eq "SSLCertificate"){
Write-Host "SSLCert Thumbprint: $sslCert"
$node.thumbprint = $sslCert
break
}
}
}else{
Write-Host "'Azure SSLCertificate Thumbprint' not set, skipping"
}
if (![string]::IsNullOrEmpty($caCert)){
foreach($node in @($xml.ServiceConfiguration.Role.Certificates.Certificate)){
if ($node.name -eq "CACertificate"){
Write-Host "CA Cert Thumbprint: $caCert"
$node.thumbprint = $caCert
break
}
}
}else{
Write-Host "'Azure CACertificate Thumbprint' not set, skipping"
}
$xml.Save($pathToCSCFG)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment