Skip to content

Instantly share code, notes, and snippets.

@faloi
Last active December 14, 2015 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faloi/5050529 to your computer and use it in GitHub Desktop.
Save faloi/5050529 to your computer and use it in GitHub Desktop.
Powershell script used to upload a package to Windows Azure. Requires Azure Powershell to work
Param(
[string]$subscription,
[string]$service,
[string]$storageAccount,
[string]$slot,
[string]$package,
[string]$configuration,
[string]$publishSettingsPath
)
#Modified and simplified version of https://www.windowsazure.com/en-us/develop/net/common-tasks/continuous-delivery/
#Usage example: .\azure_publish.ps1 -subscription "Evaluación gratuita durante tres meses" -service "parsimotion-webclient" -storageAccount "parsimotionstorage" -slot "staging" -package "C:\Users\feder_000\Documents\Workspace\parsimotion\web-client\WebClient.Azure\bin\Debug\app.publish\WebClient.Azure.cspkg" -configuration "C:\Users\feder_000\Documents\Workspace\parsimotion\web-client\WebClient.Azure\bin\Debug\app.publish\ServiceConfiguration.Cloud.cscfg" -publishSettingsPath "evaluacion-2-27-2013-credentials.publishsettings"
$timeStampFormat = "g"
$deploymentLabel = "ContinuousDeploy to $service v%build.number%"
Write-Output "Running Azure Imports"
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\*.psd1"
Import-AzurePublishSettingsFile $publishSettingsPath
Set-AzureSubscription -CurrentStorageAccount $storageAccount -SubscriptionName $subscription
function Publish(){
$deployment = Get-AzureDeployment -ServiceName $service -Slot $slot -ErrorVariable a -ErrorAction silentlycontinue
if ($a[0] -ne $null) {
Write-Output "$(Get-Date -f $timeStampFormat) - No deployment is detected. Creating a new deployment. "
}
if ($deployment.Name -ne $null) {
#Update deployment inplace (usually faster, cheaper, won't destroy VIP)
Write-Output "$(Get-Date -f $timeStampFormat) - Deployment exists in $servicename. Upgrading deployment."
UpgradeDeployment
} else {
CreateNewDeployment
}
}
function CreateNewDeployment()
{
write-progress -id 3 -activity "Creating New Deployment" -Status "In progress"
Write-Output "$(Get-Date -f $timeStampFormat) - Creating New Deployment: In progress"
$opstat = New-AzureDeployment -Slot $slot -Package $package -Configuration $configuration -label $deploymentLabel -ServiceName $service
$completeDeployment = Get-AzureDeployment -ServiceName $service -Slot $slot
$completeDeploymentID = $completeDeployment.deploymentid
write-progress -id 3 -activity "Creating New Deployment" -completed -Status "Complete"
Write-Output "$(Get-Date -f $timeStampFormat) - Creating New Deployment: Complete, Deployment ID: $completeDeploymentID"
}
function UpgradeDeployment()
{
write-progress -id 3 -activity "Upgrading Deployment" -Status "In progress"
Write-Output "$(Get-Date -f $timeStampFormat) - Upgrading Deployment: In progress"
# perform Update-Deployment
$setdeployment = Set-AzureDeployment -Upgrade -Slot $slot -Package $package -Configuration $configuration -label $deploymentLabel -ServiceName $service -Force
$completeDeployment = Get-AzureDeployment -ServiceName $service -Slot $slot
$completeDeploymentID = $completeDeployment.deploymentid
write-progress -id 3 -activity "Upgrading Deployment" -completed -Status "Complete"
Write-Output "$(Get-Date -f $timeStampFormat) - Upgrading Deployment: Complete, Deployment ID: $completeDeploymentID"
}
Write-Output "Create Azure Deployment"
Publish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment