Skip to content

Commit

Permalink
fix slot
Browse files Browse the repository at this point in the history
  • Loading branch information
yaananth committed Jan 23, 2016
1 parent d3b8281 commit 577e214
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 28 deletions.
60 changes: 34 additions & 26 deletions Tasks/AzureWebPowerShellDeployment/Publish-AzureWebDeployment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ $azureWebSiteError = $null
#If we're provided a WebSiteLocation, check for it and create it if necessary
if($WebSiteLocation)
{
if ($Slot)
{
Write-Host "Get-AzureWebSite -Name $WebSiteName -Slot $Slot -ErrorAction SilentlyContinue -ErrorVariable azureWebSiteError"
$azureWebSite = Get-AzureWebSite -Name $WebSiteName -Slot $Slot -ErrorAction SilentlyContinue -ErrorVariable azureWebSiteError
}
else
{
Write-Host "Get-AzureWebSite -Name $WebSiteName -ErrorAction SilentlyContinue -ErrorVariable azureWebSiteError"
$azureWebSite = Get-AzureWebSite -Name $WebSiteName -ErrorAction SilentlyContinue -ErrorVariable azureWebSiteError
if (!$Slot -and $WebSiteName -notlike '*(*)*') {
$Slot = 'Production'
}

$extraParameters = @{ }
if ($Slot) { $extraParameters['Slot'] = $Slot }

Write-Host "Get-AzureWebSite -Name $WebSiteName -ErrorAction SilentlyContinue -ErrorVariable azureWebSiteError $(if ($Slot) { "-Slot $Slot" })"

$azureWebSite = Get-AzureWebSite -Name $WebSiteName -ErrorAction SilentlyContinue -ErrorVariable azureWebSiteError @extraParameters

if($azureWebSiteError){
$azureWebSiteError | ForEach-Object { Write-Warning $_.Exception.ToString() }
}
Expand Down Expand Up @@ -147,24 +147,32 @@ if($azureWebSite) {
deployer = 'VSTS'
details = $buildUrl
})

$matchedNames = $azureWebSite.EnabledHostNames -match 'scm'

$url = [string]::Format("https://{0}.scm.azurewebsites.net/deployments/{1}",[System.Web.HttpUtility]::UrlEncode($WebSiteName),[System.Web.HttpUtility]::UrlEncode($deploymentId))

Write-Verbose "Invoke-RestMethod $url -Credential $credential -Method PUT -Body $body -ContentType `"application/json`" -UserAgent `"myuseragent`""
Write-Host "Updating deployment status"
try {
Invoke-RestMethod $url -Credential $credential -Method PUT -Body $body -ContentType "application/json" -UserAgent "myuseragent"
}
catch {
Write-Verbose $_.Exception.ToString()
$response = $_.Exception.Response
$responseStream = $response.GetResponseStream()
$streamReader = New-Object System.IO.StreamReader($responseStream)
$streamReader.BaseStream.Position = 0
$streamReader.DiscardBufferedData()
$responseBody = $streamReader.ReadToEnd()
$streamReader.Close()
Write-Warning "Cannot update deployment status for $WebSiteName - $responseBody"
if($matchedNames -and $matchedNames.count -gt 0) {
$WebSiteName = $matchedNames[0]
$url = [string]::Format("https://{0}.scm.azurewebsites.net/deployments/{1}",[System.Web.HttpUtility]::UrlEncode($WebSiteName),[System.Web.HttpUtility]::UrlEncode($deploymentId))

Write-Verbose "Invoke-RestMethod $url -Credential $credential -Method PUT -Body $body -ContentType `"application/json`" -UserAgent `"myuseragent`""
Write-Host "Updating deployment status"
try {
Invoke-RestMethod $url -Credential $credential -Method PUT -Body $body -ContentType "application/json" -UserAgent "myuseragent"
}
catch {
Write-Verbose $_.Exception.ToString()
$response = $_.Exception.Response
$responseStream = $response.GetResponseStream()
$streamReader = New-Object System.IO.StreamReader($responseStream)
$streamReader.BaseStream.Position = 0
$streamReader.DiscardBufferedData()
$responseBody = $streamReader.ReadToEnd()
$streamReader.Close()
Write-Warning "Cannot update deployment status for $WebSiteName - $responseBody"
}
}
else {
Write-Warning "Cannot get azurewebsite's scm, deployment status is not updated"
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureWebPowerShellDeployment/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 22
"Patch": 23
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureWebPowerShellDeployment/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 22
"Patch": 23
},
"demands": [
"azureps"
Expand Down

0 comments on commit 577e214

Please sign in to comment.