Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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