-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-new-or-upgrade.ps1
130 lines (102 loc) · 5.32 KB
/
deploy-new-or-upgrade.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
Param( $serviceName = "",
$storageAccountName = "",
$packageLocation = "",
$cloudConfigLocation = "",
$Environment = "Staging",
$deploymentLabel = "ContinuousDeploy to $servicename",
$timeStampFormat = "g",
$alwaysDeleteExistingDeployments = 1,
$enableDeploymentUpgrade = 1,
$selectedsubscription = "",
$subscriptionDataFile = "",
$pathToModule = "C:\Program Files\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
)
Import-Module $pathToModule
Select-AzureSubscription -SubscriptionName $selectedsubscription -SubscriptionDataFile $subscriptionDataFile
#Set-AzureSubscription -DefaultSubscription $selectedsubscription -CurrentStorageAccount $storageAccountName
$subscription = Get-AzureSubscription -Current
$subscriptionname = $subscription.subscriptionname
$subscriptionid = $subscription.subscriptionid
$slot = $environment
Set-AzureSubscription -SubscriptionName $selectedsubscription -SubscriptionDataFile $subscriptionDataFile -CurrentStorageAccount $storageAccountName
function SuspendDeployment()
{
write-progress -id 1 -activity "Suspending Deployment" -status "In progress"
Write-Output "$(Get-Date –f $timeStampFormat) - Suspending Deployment: In progress"
$suspend = Set-AzureDeployment -Status -Slot $slot -ServiceName $serviceName -NewStatus Suspended
Write-Output "$(Get-Date –f $timeStampFormat) - Suspended Deployment"
}
function DeleteDeployment()
{
SuspendDeployment
write-progress -id 2 -activity "Deleting Deployment" -Status "In progress"
Write-Output "$(Get-Date –f $timeStampFormat) - Deleting Deployment: In progress"
Remove-AzureDeployment -Slot $slot -ServiceName $serviceName
Write-Output "$(Get-Date –f $timeStampFormat) - Deleted Deployment"
}
function Publish()
{
$deployment = Get-AzureDeployment -ServiceName $serviceName -Slot $slot -ErrorVariable a -ErrorAction silentlycontinue
if ($a[0] -ne $null)
{
write-host "No deployment is detected. Creating a new deployment. "
}
#check for existing deployment and then either upgrade, delete + deploy, or cancel according to $alwaysDeleteExistingDeployments and $enableDeploymentUpgrade boolean variables
if ($deployment.Name -ne $null)
{
switch ($alwaysDeleteExistingDeployments)
{
1
{
switch ($enableDeploymentUpgrade)
{
1
{
Write-Output "$(Get-Date –f $timeStampFormat) - Deployment exists in $servicename. Upgrading deployment."
UpgradeDeployment
}
0 #Delete then create new deployment
{
Write-Output "$(Get-Date –f $timeStampFormat) - Deployment exists in $servicename. Deleting deployment."
DeleteDeployment
CreateNewDeployment
}
} # switch ($enableDeploymentUpgrade)
}
0
{
Write-Output "$(Get-Date –f $timeStampFormat) - ERROR: Deployment exists in $servicename. Script execution cancelled."
exit
}
}
} 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"
$newdeployment = New-AzureDeployment -Slot $slot -Package $packageLocation -Configuration $cloudConfigLocation -label $deploymentLabel -ServiceName $serviceName # -StorageAccountName $storageAccountName
write-progress -id 3 -activity "Created New Deployment"
$completeDeployment = Get-AzureDeployment -ServiceName $serviceName -Slot $slot
$completeDeploymentID = $completeDeployment.deploymentid
Write-Output "$(Get-Date –f $timeStampFormat) - Created New 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"
Set-AzureDeployment -Upgrade -ServiceName $serviceName -Package $packageLocation -Configuration $cloudConfigLocation -Slot $slot -Label $deploymentLabel -Mode Auto
#Update-Deployment -Slot $slot -Package $packageLocation -Configuration $cloudConfigLocation -label $deploymentLabel -ServiceName $serviceName # -StorageAccountName $storageAccountName |
$completeDeployment = Get-AzureDeployment -ServiceName $serviceName -Slot $slot
$completeDeploymentID = $completeDeployment.deploymentid
Write-Output "$(Get-Date –f $timeStampFormat) - Upgrade Deployment: Succeeded, Deployment ID: $completeDeploymentID"
}
Write-Output "$(Get-Date –f $timeStampFormat) - Azure Cloud App deploy script started."
Write-Output "$(Get-Date –f $timeStampFormat) - Preparing deployment of $deploymentLabel for $subscriptionname with Subscription ID $subscriptionid."
Publish
$deployment = Get-AzureDeployment -slot $slot -serviceName $servicename
$deploymentUrl = $deployment.Url
Write-Output "$(Get-Date –f $timeStampFormat) - Created Cloud App with URL $deploymentUrl."
Write-Output "$(Get-Date –f $timeStampFormat) - Azure Cloud App deploy script finished."