powershell - 使用 Powershell 和 Teamcity 部署云服务失败

标签 powershell azure teamcity

我尝试使用 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']

我真的很想知道这个异常。发布设置文件有效,证书有效,并且使用 Visual Studio 或 Cerebrata Azure Management Studio 可以正常工作。但是powershell部署失败。

有什么想法吗?

最佳答案

通过将 Azure Powershell 降级到以前的版本解决了这个问题。看起来 2014 年 10 月版本有一个错误。

关于powershell - 使用 Powershell 和 Teamcity 部署云服务失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26919157/

相关文章:

asp.net - Azure Web App - 限制对 API 管理的访问

python - Azure功能部署失败: "Malformed SCM_RUN_FROM_PACKAGE when uploading built content"

teamcity - TeamCity 是否支持执行其他 TeamCity 构建的构建步骤?

azure - 如何使用 Azure AD B2C 身份验证开发多用户 Xamarin.Forms 应用程序

.net - TeamCity 不从特定包源恢复 NuGet 包

reporting-services - 使用 TeamCity 部署 SSRS 2008 R2 报告项目

powershell - 如何使用 PowerShell Core 别名运行 Bash 命令?

powershell - 如何使用 PowerShell 从 Sharepoint Online 列表中获取项目?

c# - EntityFramework 6.0 CreateDatabaseIfNotExists 代码先创建数据库

powershell - 从特定 Outlook 文件夹中最近收到的电子邮件中抓取文件