我尝试使用PowerShell和Teamcity部署Cloud Service。这在过去运作良好,但我无法在新机器上运行。
这是powershell脚本:
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
%%中的值被teamcity参数值替换,这一切都很好。当我使用相同的设置和相同的publishsettings文件从我的计算机运行命令时,它可以工作。但是从Teamcity构建代理,它没有。它也不适用于teamcity构建代理机器上的powershell控制台。
日志说(用***替换了Id,名称等):
[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']
我真的很想知道这个例外。 publishsettings文件有效,证书有效,使用Visual Studio或Cerebrata Azure Management Studio正常工作。但是PowerShell部署失败了。
有什么想法吗?
答案 0 :(得分:2)
通过将Azure Powershell降级到以前的版本来解决这个问题。看起来像2014年10月发布的版本有一个错误。