问题描述
我已创建 Azure 经典类型服务连接。有什么我遗漏的吗?
然后我使用此 Azure 经典服务连接将云服务部署到 Azure。
Azure Deployment: D:\a\1\a\*.cspkg
View raw log
Starting: Azure Deployment: D:\a\1\a\*.cspkg
----------------------------------------------------------------
Task : Azure Cloud Service deployment
Description : Deploy an Azure Cloud Service
Version : 1.175.2
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-cloud-powershell-deployment
----------------------------------------------------------------
Import-Module -Name C:\Modules\azure_2.1.0\Azure\2.1.0\Azure.psd1 -Global
Import-Module -Name C:\Modules\azurerm_2.1.0\AzureRM\2.1.0\AzureRM.psd1 -Global
##[warning]The names of some imported commands from the module 'AzureRM.Websites' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs,run the
Import-Module command again with the Verbose parameter. For a list of approved verbs,type Get-Verb.
Import-Module -Name C:\Modules\azurerm_2.1.0\AzureRM.Profile\2.1.0\AzureRM.Profile.psm1 -Global
Add-AzureAccount -Credential System.Management.Automation.PSCredential
##[error]Sequence contains no elements
-
##[error]There was an error with the Azure credentials used for the deployment.
-
Finishing: Azure Deployment: D:\a\1\a\*.cspkg
PS:我使用的是经典编辑器来创建管道而不是 YAML 构建。
解决方法
通过下面的错误信息,问题很明显。喜欢这张图。
##[error]Sequence contains no elements
##[error]There was an error with the Azure credentials used for the deployment.
您需要通过以下脚本获取 $cred
。(有一些限制,更多详细信息,请阅读相关帖子。)
$username = "**.com"
$password = "***"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$secstr
Add-AzureRmAccount -Credential $cred
相关帖子
1. Visual Studio Team Services: Sequence contains no elements
2. Add-AzureRmAccount : Sequence contains no elements
,##[error]用于部署的 Azure 凭据出错。
您可以更改为使用 Certificate Based
作为验证方法。
要使用 Certificate Based
方法,您可以使用以下脚本创建 .cer 文件。
$cert = New-SelfSignedCertificate -DnsName yourdomain.cloudapp.net -CertStoreLocation "cert:\LocalMachine\My" -KeyLength 2048 -KeySpec "KeyExchange"
$password = ConvertTo-SecureString -String "your-password" -Force -AsPlainText
Export-PfxCertificate -Cert $cert -FilePath ".\my-cert-file.pfx" -Password $password
Export-Certificate -Type CERT -Cert $cert -FilePath .\my-cert-file.cer
然后你就可以得到 upload certificate with the management portal。
同时,您可以通过 .cer 文件获取公钥。
此密钥用于服务连接。
您可以参考this ticket获取问题的可能原因