Skip to content

Getting the SSL connection could not be established, see inner exception while calling Connect-AzAccount in Microsoft Hosted agent via Azure pipeline #12270

@NeilZiyan

Description

@NeilZiyan

#12026 Description

We are getting below error intermittently while running Azure PowerShell task in Microsoft Hosted agent via Azure pipeline

Issue can only be reproduced in Azure pipeline currently. The OS version is Windows_latest or Linux
You may find detailed os environment at
https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md
and
https://github.com/actions/virtual-environments/blob/master/images/linux/Ubuntu1804-README.md

Previously, it's possible to reproduce the issue in generic powershell task with below script but it's not possible now. Currently, still getting the issue intermittently with Azure PowerShell task.

$servicePrincipalId = ""
$servicePrincipalKey = ""
$tenantId = ""
$azureSubscriptionId = ""

$securePassword = ConvertTo-SecureString $servicePrincipalKey -AsPlainText -Force
$psCredential = New-Object System.Management.Automation.PSCredential ($servicePrincipalId, $securePassword)

Write-Verbose "Connect-AzAccount Started" -Verbose
$azureAccount = Connect-AzAccount -ServicePrincipal -Tenant $tenantId -Credential $psCredential -Environment AzureCloud
$azureAccount
Write-Verbose "Connect-AzAccount Completed" -Verbose

Steps to reproduce

Since the error returned before our own script, below configuration of Azure PowerShell task is good enough. 
![image](https://user-images.githubusercontent.com/46100345/85834426-ebc1ac00-b7c5-11ea-97f0-d4600276a9a5.png)

Environment data


Module versions

az_3.8.0/Az.Accounts/1.8.1/

Debug output

Since the line failed is still within build-in script of Azure PowerShell task, it's not possible to add debugpreference
2020-06-24T12:15:10.0417204Z ##[command]Import-Module -Name /usr/share/az_3.8.0/Az.Accounts/1.8.1/Az.Accounts.psd1 -Global
2020-06-24T12:15:10.4162733Z ##[command]Clear-AzContext -Scope Process
2020-06-24T12:15:11.3283361Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2020-06-24T12:15:11.9323163Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
2020-06-24T12:15:29.3785853Z Exception is : An error occurred while sending the request.
2020-06-24T12:15:29.5508541Z [91mOperationStopped: [0m/home/vsts/work/_tasks/AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62/4.168.2/InitializeAz.ps1:91
2020-06-24T12:15:29.5509671Z [96mLine |
2020-06-24T12:15:29.5510362Z [96m 91 | [0m [96mthrow (New-Object System.Exception("There was an error with t [0m …
2020-06-24T12:15:29.5511438Z [96m | [91m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020-06-24T12:15:29.5512227Z [91m [96m | [91mThere was an error with the service principal used for the
2020-06-24T12:15:29.5512876Z [96m | [91mdeployment.
2020-06-24T12:15:29.5513342Z [0m
2020-06-24T12:15:29.5638014Z ##[debug]Exit code 1 received from tool '/usr/bin/pwsh'
2020-06-24T12:15:29.5645783Z ##[debug]STDIO streams have closed for tool '/usr/bin/pwsh'
2020-06-24T12:15:29.5660119Z ##[debug]task result: Failed

## Error output

<!-- Please run Resolve-AzError and paste the output in the below code block -->

Again, it's in Azure PowerShell task, not possible to add this flag.

In the latest version of Azure Powershell task, it seems the actual error is covered. In version 4.* Azure PowerShell task, we see below error. 
2020-04-30T21:42:13.2641704Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
2020-04-30T21:42:24.4607635Z ##[error]An error occurred while sending the request.
2020-04-30T21:42:24.4621509Z ##[debug]Processed: ##vso[task.logissue type=error]An error occurred while sending the request.
2020-04-30T21:42:24.4998910Z ##[error]Make sure the machine is using TLS 1.2 protocol or higher. Check https://aka.ms/enableTlsv2 for more information on how to enable TLS in your machine.
2020-04-30T21:42:24.5000844Z ##[debug]Processed: ##vso[task.logissue type=error]Make sure the machine is using TLS 1.2 protocol or higher. Check https://aka.ms/enableTlsv2 for more information on how to enable TLS in your machine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions