【发布时间】:2014-11-13 21:54:38
【问题描述】:
我尝试使用 powershell 和 Teamcity 部署云服务。这在过去运行良好,但我无法让它在新机器上运行。
这是 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 参数值,这一切都很好。当我使用相同的设置和相同的发布设置文件从我的计算机运行命令时,它可以工作。但是从 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 部署失败。
有什么想法吗?
【问题讨论】:
-
你应该标记 teamcity,因为它不是真正的 powershell 问题
-
添加了 teamcity 标签,谢谢。我不确定这是否真的是 teamcity 或 powershell azure cmdlet 问题,因为它也无法从代理机器上的 powershell 控制台工作。但它可以在我的机器上运行。
标签: powershell azure teamcity