0

I have suddenly started getting this error on some of the agents that are installed on my Agent Pool. All of them are on the same Virtual Machine:

2022-06-13T11:07:24.5665998Z ##[command]"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\Agent\02\_work\_temp\3c5c143c-117b-4adb-9c90-7043632edfa0.ps1'"
2022-06-13T11:07:26.0076950Z Added TLS 1.2 in session.
2022-06-13T11:07:26.1347095Z ##[command]Import-Module -Name C:\Program Files\PowerShell\Modules\Az.Accounts\2.8.0\Az.Accounts.psd1 -Global
2022-06-13T11:07:26.8410918Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2022-06-13T11:07:27.4110901Z ##[command]Clear-AzContext -Scope Process
2022-06-13T11:07:27.4789914Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant {{Redacted}} -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
2022-06-13T11:07:27.5295739Z ##[error]Unable to find environment with name 'AzureCloud'
2022-06-13T11:07:27.6855841Z ##[error]There was an error with the service principal used for the deployment.
2022-06-13T11:07:27.7936958Z ##[error]PowerShell exited with code '1'.
2022-06-13T11:07:29.5169529Z ##[command]Disconnect-AzAccount -Scope Process -ErrorAction Stop
2022-06-13T11:07:29.9206643Z ##[command]Clear-AzContext -Scope Process -ErrorAction Stop

I have tried uninstalling and installing azure powershell, but the error persist. Also agents which are using the same service connection on a different VM are deploying without any issues.

Finally I tried to run the command locally on my VM and it succeeded, so I am not sure what could be causing this error.

paddingtonMike
  • 1,441
  • 1
  • 21
  • 37

1 Answers1

0

From the error message, it may cause by Azure PowerShell Module.

You could try uninstall the Az PowerShell module locally on your VM : https://learn.microsoft.com/en-us/powershell/azure/uninstall-az-ps?view=azps-8.0.0

And re-install for "AllUsers" scope:

Install-Module -Name Az -Scope AllUsers -Repository PSGallery -Force
Kim Xu-MSFT
  • 1,819
  • 1
  • 2
  • 4