1
votes

I try to deploy a Cloud Service using powershell and Teamcity. This worked fine in the past, but I cannot make it work on a new machine.

This is the powershell script:

Write-Output "$(Get-Date -f g) - Running Azure Imports"
Import-AzurePublishSettingsFile -PublishSettingsFile "%publishSettingsFileName%"
Set-AzureSubscription -CurrentStorageAccountName "%blobAccountName%" -SubscriptionName "%subscriptionName%"
Select-AzureSubscription -SubscriptionName "%subscriptionName%"

function Publish(){
 $deployment = Get-AzureDeployment -ServiceName "%cloudServiceName%" -Slot "%cloudServiceSlot%" -ErrorVariable a -ErrorAction silentlycontinue 
 if ($a[0] -ne $null) {
    Write-Output "$(Get-Date -f g) - 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 g) - Deployment exists in %cloudServiceName%.  Upgrading deployment."
    UpgradeDeployment
 } else {
    CreateNewDeployment
 }
}

function CreateNewDeployment()
{
    write-progress -id 3 -activity "Creating New Deployment" -Status "In progress"
    Write-Output "$(Get-Date -f g) - Creating New Deployment: In progress"

    $opstat = New-AzureDeployment -Slot "%cloudServiceSlot%" -Package "%packageUrl%" -Configuration "%cscfgFileName%" -label "%deploymentLabel%" -ServiceName "%cloudServiceName%"
    $completeDeployment = Get-AzureDeployment -ServiceName "%cloudServiceName%" -Slot "%cloudServiceSlot%"
    $completeDeploymentID = $completeDeployment.deploymentid

    write-progress -id 3 -activity "Creating New Deployment" -completed -Status "Complete"
    Write-Output "$(Get-Date -f g) - Creating New Deployment: Complete, Deployment ID: $completeDeploymentID"
}

function UpgradeDeployment()
{
    write-progress -id 3 -activity "Upgrading Deployment" -Status "In progress"
    Write-Output "$(Get-Date -f g) - Upgrading Deployment: In progress"

    $opstat = Set-AzureDeployment -Upgrade -Slot "%cloudServiceSlot%" -Package "%packageUrl%" -Configuration "%cscfgFileName%" -label "%deploymentLabel%" -ServiceName "%cloudServiceName%" -Force
    $completeDeployment = Get-AzureDeployment -ServiceName "%cloudServiceName%" -Slot "%cloudServiceSlot%"
    $completeDeploymentID = $completeDeployment.deploymentid

    write-progress -id 3 -activity "Upgrading Deployment" -completed -Status "Complete"
    Write-Output "$(Get-Date -f g) - Upgrading Deployment: Complete, Deployment ID: $completeDeploymentID"
}

Write-Output "$(Get-Date -f g) - Create Azure Deployment"
Publish

The values in %% are replaced by teamcity parameter values, this is all fine. When I run the commands from my computer using the same settings and the same publishsettings-file, it works. But from Teamcity build agent, it does not. It also does not work from powershell console on the teamcity build agent machine.

Log says (replaced Id, Name etc. with ***):

[22:45:47] :     [Step 2/2] ##teamcity[buildStatisticValue key='buildStageDuration:buildStepRUNNER_193' value='0.0']
[22:45:47] :     [Step 2/2] Starting:  C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NoProfile -NonInteractive -ExecutionPolicy ByPass -Command - < E:\BuildAgent1\temp\buildTmp\powershell2886801367807761703.ps1
[22:45:47] :     [Step 2/2] in directory: E:\BuildAgent1\work\a355cf3c0001cfa2
[22:45:49] :     [Step 2/2] 13.11.2014 22:45 - Running Azure Imports
[22:45:50] :     [Step 2/2] 
[22:45:50] :     [Step 2/2] 
[22:45:50] :     [Step 2/2] Id          : ***
[22:45:50] :     [Step 2/2] Name        : ***
[22:45:50] :     [Step 2/2] Environment : AzureCloud
[22:45:50] :     [Step 2/2] Account     : ***
[22:45:50] :     [Step 2/2] Properties  : {[SupportedModes, AzureServiceManagement]}
[22:45:50] :     [Step 2/2] 
[22:45:50] :     [Step 2/2] 
[22:45:50] :     [Step 2/2] 
[22:45:50] :     [Step 2/2] 
[22:45:50] :     [Step 2/2] 
[22:45:50] :     [Step 2/2] Id          : ***
[22:45:50] :     [Step 2/2] Name        : ***
[22:45:50] :     [Step 2/2] Environment : AzureCloud
[22:45:50] :     [Step 2/2] Account     : ***
[22:45:50] :     [Step 2/2] Properties  : {[SupportedModes, AzureServiceManagement], [Default, True], 
[22:45:50] :     [Step 2/2]               [StorageAccount, ***]}
[22:45:50] :     [Step 2/2] 
[22:45:50] :     [Step 2/2] 
[22:45:50] :     [Step 2/2] 
[22:45:50] :     [Step 2/2] 13.11.2014 22:45 - Create Azure Deployment
[22:45:52]W:     [Step 2/2] Get-AzureDeployment : An error occurred while sending the request.
[22:45:52]W:     [Step 2/2] In Zeile:2 Zeichen:16
[22:45:52]W:     [Step 2/2] +  $deployment = Get-AzureDeployment -ServiceName "***" -Slot 
[22:45:52]W:     [Step 2/2] "Production" ...
[22:45:52]W:     [Step 2/2] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[22:45:52]W:     [Step 2/2] ~~~
[22:45:52]W:     [Step 2/2]     + CategoryInfo          : NotSpecified: (:) [Get-AzureDeployment], HttpReq 
[22:45:52]W:     [Step 2/2]    uestException
[22:45:52]W:     [Step 2/2]     + FullyQualifiedErrorId : System.Net.Http.HttpRequestException,Microsoft.W 
[22:45:52]W:     [Step 2/2]    indowsAzure.Commands.ServiceManagement.HostedServices.GetAzureDeploymentCo  
[22:45:52]W:     [Step 2/2]   mmand
[22:45:52]W:     [Step 2/2]  
[22:45:52] :     [Step 2/2] 13.11.2014 22:45 - No deployment is detected. Creating a new deployment. 
[22:45:52] :     [Step 2/2] 13.11.2014 22:45 - Creating New Deployment: In progress
[22:45:53]W:     [Step 2/2] New-AzureDeployment : An error occurred while sending the request.
[22:45:53]W:     [Step 2/2] In Zeile:5 Zeichen:15
[22:45:53]W:     [Step 2/2] +     $opstat = New-AzureDeployment -Slot "Production" -Package 
[22:45:53]W:     [Step 2/2] "http://*** ...
[22:45:53]W:     [Step 2/2] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[22:45:53]W:     [Step 2/2] ~~~
[22:45:53]W:     [Step 2/2]     + CategoryInfo          : NotSpecified: (:) [New-AzureDeployment], HttpReq 
[22:45:53]W:     [Step 2/2]    uestException
[22:45:53]W:     [Step 2/2]     + FullyQualifiedErrorId : System.Net.Http.HttpRequestException,Microsoft.W 
[22:45:53]W:     [Step 2/2]    indowsAzure.Commands.ServiceManagement.HostedServices.NewAzureDeploymentCo  
[22:45:53]W:     [Step 2/2]   mmand
[22:45:53]W:     [Step 2/2]  
[22:45:54]W:     [Step 2/2] Get-AzureDeployment : An error occurred while sending the request.
[22:45:54]W:     [Step 2/2] In Zeile:6 Zeichen:27
[22:45:54]W:     [Step 2/2] +     $completeDeployment = Get-AzureDeployment -ServiceName "***" 
[22:45:54]W:     [Step 2/2] -Slot " ...
[22:45:54]W:     [Step 2/2] +                           
[22:45:54]W:     [Step 2/2] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[22:45:54]W:     [Step 2/2]     + CategoryInfo          : NotSpecified: (:) [Get-AzureDeployment], HttpReq 
[22:45:54]W:     [Step 2/2]    uestException
[22:45:54]W:     [Step 2/2]     + FullyQualifiedErrorId : System.Net.Http.HttpRequestException,Microsoft.W 
[22:45:54]W:     [Step 2/2]    indowsAzure.Commands.ServiceManagement.HostedServices.GetAzureDeploymentCo  
[22:45:54]W:     [Step 2/2]   mmand
[22:45:54]W:     [Step 2/2]  
[22:45:54] :     [Step 2/2] 13.11.2014 22:45 - Creating New Deployment: Complete, Deployment ID: 
[22:45:54] :     [Step 2/2] Process exited with code 0
[22:45:54] :     [Step 2/2] ##teamcity[buildStatisticValue key='buildStageDuration:buildStepRUNNER_193' value='7118.0']

I am really wondering about this exception. The publishsettings file is valid, the certificate is valid and works fine using Visual Studio or Cerebrata Azure Management Studio. But powershell deployment fails.

Any ideas?

1
you should tag teamcity since its not really a powershell problem - Paul
added the teamcity tag, thank you. i am not sure if it is really a teamcity or a powershell azure cmdlets problem, because it also does not work from the powershell console on the agent machine. but it works from my machine. - Carsten Schütte

1 Answers

2
votes

Solved it by downgrading Azure Powershell to previous version. Looks like October 2014 release has a bug here.