Search code examples
azure-devopsazure-cloud-services

I am getting the "Sequence contains no elements error" while running a build pipeline in Azure DevOps services to deploy a cloud service (classic)


I have created an Azure Classic type service connection. Is there anything I am missing?

I am then using this Azure Classic Service connection to deploy the cloud service to 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://learn.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: I am using the classic editor to create the pipelines and not YAML builds.


Solution

  • ##[error]There was an error with the Azure credentials used for the deployment.

    You could change to use the Certificate Based as the verification method.

    enter image description here

    To use the Certificate Based method, you could use the following script to create the .cer file.

    $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
    

    Then you could get the upload certificate with the management portal.

    At the same time , you could get the Public key with .cer file.

    enter image description here

    This key is used in the service connection.

    You can refer to this ticket to get the possible cause of the problem