服务器无法验证请求.验证证书是否有效并与此订阅相关联

Aak*_*ash 3 deployment powershell teamcity automation azure

尝试编写脚本以在Azure上创建的VM上自动部署Azure.昨天一切都很花花公子.我进行了设置,并且服务正在部署到各自的订阅中.

我的证书区域还有许多Azure管理证书.我已经把它们全部清理干净了,因为除了一个人以外都很老了.然后我重新导入了最新的发布设置文件,希望通过从头开始,一切都会很高兴.

然后我今天登录,运行了我的一个部署,它说:

The server failed to authenticate the request. 
Verify that the certificate is valid and is associated with this subscription.
Run Code Online (Sandbox Code Playgroud)

没问题,只需使用方便的dandy add-azureaccount,它会重新登录,重新运行部署,然后再说:

Set-AzureService : ForbiddenError: The server failed to authenticate the
request. Verify that the certificate is valid and is associated with this
subscription.
Run Code Online (Sandbox Code Playgroud)

有没有人知道如何获得服务器的身份验证?

我在Azure上创建并在VM上安装Teamcity的所有这些自动化.当我尝试直接在VM Powershell上运行脚本时它工作正常但是当我尝试运行Teamcity配置时发生错误,它在PowerShell构建步骤中失败.

It though returns the subscriptions that are there on VM by the command Get-AzureSubscription

[11:31:07][Step 3/3] SubscriptionId :*******

[11:31:07][Step 3/3] SubscriptionName :****

[11:31:07][Step 3/3] Environment : AzureCloud

[11:31:07][Step 3/3] SupportedModes : AzureServiceManagement

[11:31:07][Step 3/3] DefaultAccount :*******

[11:31:07][Step 3/3] Accounts :*******

[11:31:07][Step 3/3] IsDefault : True

[11:31:07][Step 3/3] IsCurrent : True

[11:31:07][Step 3/3] CurrentStorageAccountName :*******

[11:31:07][Step 3/3] TenantId :

[11:31:07][Step 3/3] SubscriptionId :*******

[11:31:07][Step 3/3] SubscriptionName :*******

[11:31:07][Step 3/3] Environment : AzureCloud

[11:31:07][Step 3/3] SupportedModes : AzureServiceManagement

[11:31:07][Step 3/3] DefaultAccount :*******

[11:31:07][Step 3/3] Accounts :*******

[11:31:07][Step 3/3] IsDefault : False

[11:31:07][Step 3/3] IsCurrent : False

[11:31:07][Step 3/3] CurrentStorageAccountName : tarifficapi

[11:31:07][Step 3/3] TenantId :

[11:31:07][Step 3/3]

[11:31:07][Step 3/3]

[11:31:07][Step 3/3]

[11:31:21][Step 3/3] Set-AzureService : ForbiddenError: The server failed to >authenticate the

[11:31:21][Step 3/3] request. Verify that the certificate is valid and is >associated with this

[11:31:21][Step 3/3] subscription.

[11:31:21][Step 3/3] At line:1 char:1

[11:31:21][Step 3/3] + Set-AzureService -ServiceName $service -Label $deploymentLabel

[11:31:21][Step 3/3] + >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [11:31:21][Step 3/3] + CategoryInfo : CloseError: (:) [Set->AzureService], ComputeCloud

[11:31:21][Step 3/3] Exception

[11:31:21] [第3/3步] + FullyQualifiedErrorId:> Microsoft.WindowsAzure.Commands.ServiceManagemen

[11:31:21] [步骤3/3] t.HostedServices.SetAzureServiceCommand

任何人都可以知道这里出了什么问题吗?

Aak*_*ash 6

我终于得到了解决方案

我收到的错误消息是

Set-AzureService:ForbiddenError:服务器无法验证请求.验证证书是否有效并与此>订阅相关联.

这有点误导,因为你可以在下面的代码中看到(特别是:最后一行),我确实设置了当前的存储空间,但为什么我收到此消息?

[05:14:33] [步骤3/3] Set-AzureService:ForbiddenError:服务器无法验证[05:14:33] [步骤3/3]请求.验证证书是否有效并且与[05:14:33] [步骤3/3]订阅相关联.[05:14:33] [步骤3/3]行:1字符:1 [05:14:33] [步骤3/3] + Set-AzureService -ServiceName $ service -Label> $ deploymentLabel [05:14 :33] [步骤3/3] +> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~ [05:14:33] [第3/3步] + CategoryInfo:CloseError:(:) [Set-> AzureService] ,ComputeCloud [05:14:33] [第3/3步]异常[05:14:33] [第3/3步] + FullyQualifiedErrorId:> Microsoft.WindowsAzure.Commands.ServiceManagemen [05:14:33] [第3步/ 3] t.HostedServices.SetAzureServiceCommand

在VM Powershell中运行时脚本运行正常但在使用Teamcity运行时失败.

要解决此问题,我按照以下步骤操作:

在VM上打开Windows Powershell

  • 运行"Get-AzurePublishSettingsFile".它将要求您登录Azure,您将获得与您的帐户关联的Azure订阅的发布设置文件.
  • 然后运行"Add-AzureAccount",它将要求您登录,您的帐户将被添加到powershell.登录Azure Portal(manage.windowsazure.com).
  • 转到设置=>管理证书部分.获取最近添加的PublishSettingCertificate的ThumbPrint.
  • 在Powershell上运行Import-AzurePublishSettingsFile"VM上发布设置文件的路径"
  • 运行Add-AzureCertificate -serviceName"您的服务名称"-certToDeploy(获取项目证书:\ CurrentUser\MY"您从Azure获得的证书ThumbPrint")最后"Get-AzureSubscription",以查看在Powershell上添加的订阅.

希望这有助于一些:)