ADO Release pipeline AzurePowershell task fails on Connect-AzAccount - azure

I have a very annoying issue with one of our servers running our self-hosted agents.
We have a Release pipeline containing Azure Powershell tasks (Task version 5.*). The 'Use PowerShell Core' is switched on.
The scripts run perfectly on 'server_1', but on 'server_2' the task fails during initialisation / Connect-AzAccount. Please note that the logging below is thus the initialisation of the Azure Powershell task, and not our own script.
Log 'server_1':
2022-10-04T13:20:47.8917865Z ##[command]Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\1.6.6\Az.Accounts.psd1 -Global
2022-10-04T13:20:48.8314051Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2022-10-04T13:20:50.2298081Z ##[command]Clear-AzContext -Scope Process
2022-10-04T13:20:50.3313243Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant xxxxxxxxxxxxxxxxxx -Credential System.Management.Automation.PSCredential -Environment AzureCloud #processScope
2022-10-04T13:20:51.1463087Z ##[command] Set-AzContext -SubscriptionId yyyyyyyyyyyyyyyyyyyy -TenantId xxxxxxxxxxxxxxxxxx
2022-10-04T13:20:52.4233903Z ## Az module initialization Complete
2022-10-04T13:20:52.4241534Z ## Beginning Script Execution
Log 'server_2':
2022-10-04T12:54:16.3415330Z ##[command]Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\Az.Accounts\1.6.6\Az.Accounts.psd1 -Global
2022-10-04T12:54:17.0951601Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2022-10-04T12:54:17.4023735Z ##[command]Clear-AzContext -Scope Process
2022-10-04T12:54:17.4838081Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant xxxxxxxxxxxxxxxxxx -Credential System.Management.Automation.PSCredential -Environment AzureCloud #processScope
2022-10-04T12:54:17.6673926Z ##[error]Unable to read beyond the end of the stream.
2022-10-04T12:54:17.6860076Z ##[error]Initializing Az module failed: For troubleshooting, refer: https://aka.ms/azurepowershelltroubleshooting
2022-10-04T12:54:17.7781536Z ##[error]There was an error with the service principal used for the deployment.
The versions of Azure Powershell modules Az, and Az.Accounts are the same on both servers.
POwershell 5 and Powershell 7 has been installed on both servers.
'server_1' OS is Windows Server 2016 Datacenter
'server_2' OS is Windows Server 2012 R2 Datacenter
When I run a Powershell 5 console on the servers and use Connect-AzAccount using a service principle I also see the same behaviour (server_1 successful, server_2 unsuccessful).
The details of the -debug are:
DEBUG: AzureQoSEvent: CommandName - Connect-AzAccount; IsSuccess - False; Duration - 00:00:47.2917018; Exception - System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
at System.IO.__Error.EndOfFile()
at System.IO.MemoryStream.InternalReadInt32()
at Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache.Deserialize(Byte[] state)
at Microsoft.Azure.Commands.Common.Authentication.Core.ProtectedFileTokenCache.ReadFileIntoCache(String cacheFileName)
at Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache.OnBeforeAccess(TokenCacheNotificationArgs args)
at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.<RunAsync>d__57.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenForClientCommonAsync>d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenAsync>d__56.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Commands.Common.Authentication.ServicePrincipalTokenProvider.AcquireTokenWithCertificate(AdalConfiguration config, String appId, String thumbprint)
at Microsoft.Azure.Commands.Common.Authentication.ServicePrincipalTokenProvider.GetAccessTokenWithCertificate(AdalConfiguration config, String clientId, String certificateThumbprint, String credentialType)
at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory.Authenticate(IAzureAccount account, IAzureEnvironment environment, String tenant, SecureString password, String promptBehavior, Action`1 promptAction,
IAzureTokenCache tokenCache, String resourceId)
at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.AcquireAccessToken(IAzureAccount account, IAzureEnvironment environment, String tenantId, SecureString password, String promptBehavior, Action`1 promptAction)
at Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient.Login(IAzureAccount account, IAzureEnvironment environment, String tenantId, String subscriptionId, String subscriptionName, SecureString password, Boolean
skipValidation, Action`1 promptAction, String name, Boolean shouldPopulateContextList)
at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.<>c__DisplayClass92_0.<ExecuteCmdlet>b__0(AzureRmProfile localProfile, RMProfileClient profileClient, String name)
at Microsoft.Azure.Commands.Profile.Common.AzureContextModificationCmdlet.ModifyContext(Action`2 contextAction)
at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.SetContextWithOverwritePrompt(Action`3 setContextAction)
at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
Questions:
What could cause this issue on failing task when it runs using on 'server_2', while succeeding on 'server_1', or how could I find the root cause of the ##[error] logs, so this leads to the solution to solve this.

Related

Azure Powershell script throwing 'Forbidden'

I have a powershell script that is throwing error. I am trying to create an Alert Action Group through powershell. The last line is throwing error.
$TenantId = Get-AzTenant | select Id
Connect-AzAccount -TenantId $TenantId.Id -SubscriptionName $SubscriptionName
$Receiver1 = New-AzActionGroupReceiver -Name $ActionGroupReceiver -EmailReceiver -EmailAddress $EmailAddress
Set-AzActionGroup -Name $ActionGroup -ResourceGroup $Rg -ShortName $ActionGroupShortName -Receiver $Receiver1
I have Owner access to the subscription and can confirm that all of these variables have appropriate values.
The same code worked for a different subscription in the same tenant where I have contributor access. This is probably an access issue however I am not able to figure why I am getting Forbidden even with Owner access.
Edit - Error text
Set-AzActionGroup : Exception type: ErrorResponseException, Message:
Microsoft.Azure.Management.Monitor.Models.ErrorResponseException: Operation returned an invalid status code 'Forbidden'
at Microsoft.Azure.Management.Monitor.ActionGroupsOperations.d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Management.Monitor.ActionGroupsOperationsExtensions.d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Management.Monitor.ActionGroupsOperationsExtensions.CreateOrUpdate(IActionGroupsOperations
operations, String resourceGroupName, String actionGroupName, ActionGroupResource actionGroup)
at Microsoft.Azure.Commands.Insights.ActionGroups.SetAzureRmActionGroupCommand.ProcessRecordInternal()
at Microsoft.Azure.Commands.Insights.MonitorCmdletBase.ExecuteCmdlet(), Code: Null, Status code:Null, Reason
phrase: Null
At C:\Users\YashTamakuwala\Desktop\live_traffic\Alerts\Alerts\CreateActionGroup.ps1:25 char:1
Set-AzActionGroup -Name $ActionGroup -ResourceGroup $Rg -ShortName $A ...
+ CategoryInfo : CloseError: (:) [Set-AzActionGroup], PSInvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.ActionGroups.SetAzureRmActionGroupCommand
I found the problem. I tried performing the same action through portal but couldn't. Got this error.
There were policies in place to prevent such activities. Also, the requests from powershell are tracked in Activity Logs which in hindsight, I should have looked into. So I temporarily disabled the policies and was able to run the script successfully.

AzCopy v10.5.1: error copying from file share to blob container

I'm getting an error trying to copy all files from an Azure File Share to a Blob Container within the same Storage account.
$rg = "[REDACTED]"
$storageAccount = "[REDACTED]"
$storageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $rg -AccountName $storageAccount ).Value[0]
$context = New-AzStorageContext -StorageAccountName $storageAccount -StorageAccountKey $storageAccountKey
$sourceSAS = New-AzStorageShareSASToken -Context $context -ExpiryTime (Get-Date).AddHours(24*3) -Permission "rdw" -ShareName "[REDACTED]" -FullUri
$destSAS = New-AzStorageContainerSASToken -Context $context -ExpiryTime (Get-Date).AddHours(24*3) -Permission "rdw" -Name "[REDACTED]" -FullUri
azcopy.exe copy $sourceSAS $destSAS --recursive=true
and getting this error:
INFO: Scanning...
INFO: Failed to create one or more destination container(s). Your transfers may still succeed if the container already exists.
INFO: Any empty folders will not be processed, because source and/or destination doesn't have full folder support
failed to perform copy command due to error: cannot start job due to error: cannot list files due to reason -> github.com/Azure/azure-storage-blob-go/azblob.newStorageError, /home/vsts/go/pkg/mod/github.com/!azure/azure-storage-blob-go#v0.10.0/azblob/zc_storage_error.go:42
===== RESPONSE ERROR (ServiceCode=AuthorizationPermissionMismatch) =====
Description=This request is not authorized to perform this operation using this permission.
RequestId:b0027090-a01e-0088-18c7-6ff7a6000000
Time:2020-08-11T10:08:06.6069744Z, Details:
Code: AuthorizationPermissionMismatch
GET https://[REDACTED].blob.core.windows.net/[REDACTED]?comp=list&delimiter=%2F&include=metadata&restype=container&se=2020-08-14t10%3A03%3A25z&sig=-REDACTED-&sp=rwd&sr=c&sv=2018-11-09&timeout=901
User-Agent: [AzCopy/10.5.1 Azure-Storage/0.10 (go1.13; Windows_NT)]
X-Ms-Client-Request-Id: [efe44227-df00-47e1-74e4-f7a8670e0ace]
X-Ms-Version: [2019-02-02]
--------------------------------------------------------------------------------
RESPONSE Status: 403 This request is not authorized to perform this operation using this permission.
Content-Length: [279]
Content-Type: [application/xml]
Date: [Tue, 11 Aug 2020 10:08:06 GMT]
Server: [Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0]
X-Ms-Client-Request-Id: [efe44227-df00-47e1-74e4-f7a8670e0ace]
X-Ms-Error-Code: [AuthorizationPermissionMismatch]
X-Ms-Request-Id: [b0027090-a01e-0088-18c7-6ff7a6000000]
X-Ms-Version: [2019-02-02]
if I try these 2 work fine:
azcopy.exe copy "C:\TEMP" $destSAS --recursive=true
azcopy.exe copy "C:\TEMP" $sourceSAS --recursive=true
I have Owner access role in the subscription.
I found this issue in github and posted there:
https://github.com/Azure/azure-storage-azcopy/issues/518
Any ideas?
Cheers
When you request the SAS token, you need to make sure you grant list permission as well, the correct syntax for this is rwdl. I have included the reference for the command as well should you need it here.

Azure file copy Task - [error]Object reference not set to an instance of an object

Within Azure DevOps I have a release pipeline that uses the Azure file copy # version 2.154.19 to copy some files to blob storage.
Recently, the task started to fail with the following error in the logs:
2020-02-03T11:15:33.0304141Z ##[error]Object reference not set to an instance of an object.
The full task logs from Azure DevOps are as follows
2020-02-03T11:15:14.5316566Z ##[section]Starting: AzureBlob File Copy
2020-02-03T11:15:14.5429010Z ==============================================================================
2020-02-03T11:15:14.5429097Z Task : Azure file copy
2020-02-03T11:15:14.5429168Z Description : Copy files to Azure Blob Storage or virtual machines
2020-02-03T11:15:14.5429219Z Version : 2.154.19
2020-02-03T11:15:14.5429281Z Author : Microsoft Corporation
2020-02-03T11:15:14.5429338Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-file-copy
2020-02-03T11:15:14.5429551Z ==============================================================================
2020-02-03T11:15:17.6071596Z ##[command]Import-Module -Name C:\Modules\azurerm_2.1.0\AzureRM\2.1.0\AzureRM.psd1 -Global
2020-02-03T11:15:29.5994320Z ##[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.
2020-02-03T11:15:29.6177486Z ##[command]Import-Module -Name C:\Modules\azurerm_2.1.0\AzureRM.Profile\2.1.0\AzureRM.Profile.psm1 -Global
2020-02-03T11:15:30.0756632Z ##[command]Add-AzureRMAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -EnvironmentName AzureCloud #processScope
2020-02-03T11:15:31.2123104Z ##[command] Select-AzureRMSubscription -SubscriptionId 4fc034ca-6877-4bfd-83a6-5ffe29608da5 -TenantId ***
2020-02-03T11:15:33.0304141Z ##[error]Object reference not set to an instance of an object.
2020-02-03T11:15:33.0638228Z ##[section]Finishing: AzureBlob File Copy
The configuration for the task is as follows:
Nothing has changed recently but this task now seems to be failing.
I've set the variable system.debug to true and now I get the following logs:
2020-02-04T13:12:06.4274088Z ##[debug]Validating minimum required azure powershell version is greater than or equal to 0.9.0
2020-02-04T13:12:06.4332040Z ##[debug]Populating RepositorySourceLocation property for module AzureRM.
2020-02-04T13:12:06.4360442Z ##[debug]Loading module from path 'C:\Modules\azurerm_2.1.0\AzureRM\2.1.0\AzureRM.psm1'.
2020-02-04T13:12:06.4556756Z ##[debug]Installed Azure PowerShell version: 2.1.0
2020-02-04T13:12:06.4579801Z ##[debug]Compare azure versions: 2.1.0, 0.9.0
2020-02-04T13:12:06.4599735Z ##[debug]Validated the required azure powershell version is greater than or equal to 0.9.0
2020-02-04T13:12:06.4685961Z ##[debug][Azure Call]Getting resource details for azure storage account resource: xxx221 with resource type: Microsoft.Storage/storageAccounts
2020-02-04T13:12:07.0852040Z ##[debug]System.NullReferenceException: Object reference not set to an instance of an object.
2020-02-04T13:12:07.0865383Z ##[debug] at Microsoft.Azure.Commands.Management.Storage.Models.PSStorageAccount..ctor(StorageAccount storageAccount) in d:\workspace\powershell-sign\src\ResourceManager\Storage\Commands.Management.Storage\Models\PSStorageAccount.cs:line 27
2020-02-04T13:12:07.0880480Z ##[debug] at Microsoft.Azure.Commands.Management.Storage.Models.PSStorageAccount.Create(StorageAccount storageAccount, IStorageManagementClient client) in d:\workspace\powershell-sign\src\ResourceManager\Storage\Commands.Management.Storage\Models\PSStorageAccount.cs:line 87
2020-02-04T13:12:07.0894045Z ##[debug] at Microsoft.Azure.Commands.Management.Storage.StorageAccountBaseCmdlet.<>c__DisplayClass2.<WriteStorageAccountList>b__1(StorageAccount storageAccount) in d:\workspace\powershell-sign\src\ResourceManager\Storage\Commands.Management.Storage\StorageAccount\StorageAccountBaseCmdlet.cs:line 161
2020-02-04T13:12:07.0908039Z ##[debug] at Microsoft.WindowsAzure.Commands.Utilities.Common.GeneralUtilities.ForEach[T](IEnumerable`1 sequence, Action`1 action) in d:\workspace\powershell-sign\src\Common\Commands.Common\GeneralUtilities.cs:line 147
2020-02-04T13:12:07.0923496Z ##[debug] at Microsoft.Azure.Commands.Management.Storage.StorageAccountBaseCmdlet.WriteStorageAccountList(IEnumerable`1 storageAccounts) in d:\workspace\powershell-sign\src\ResourceManager\Storage\Commands.Management.Storage\StorageAccount\StorageAccountBaseCmdlet.cs:line 161
2020-02-04T13:12:07.0938702Z ##[debug] at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() in d:\workspace\powershell-sign\src\Common\Commands.Common\AzurePSCmdlet.cs:line 610
2020-02-04T13:12:07.1882171Z ##[debug]Processed: ##vso[task.logissue type=error;code={"Task_Internal_Error":"TemporaryCopyingToBlobContainerFailed"};]
2020-02-04T13:12:07.1928893Z ##[debug]Trying to disconnect from Azure and clear context at process scope
2020-02-04T13:12:07.4018399Z ##[debug]Caught exception from task script.
2020-02-04T13:12:07.4054453Z ##[debug]Error record:
2020-02-04T13:12:07.4764182Z ##[debug]Get-AzureRmStorageAccount : Object reference not set to an instance of an object.
2020-02-04T13:12:07.4779906Z ##[debug]At D:\a\_tasks\AzureFileCopy_eb72cb01-a7e5-427b-a8a1-1b31ccac8a43\2.154.19\AzureUtilityGTE1.0.ps1:27 char:47
2020-02-04T13:12:07.4795063Z ##[debug]+ ... ResourceDetails = Get-AzureRmStorageAccount -ErrorAction Stop | Where ...
2020-02-04T13:12:07.4809226Z ##[debug]+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020-02-04T13:12:07.4822827Z ##[debug] + CategoryInfo : CloseError: (:) [Get-AzureRmStorageAccount], NullReferenceException
2020-02-04T13:12:07.4836831Z ##[debug] + FullyQualifiedErrorId : Microsoft.Azure.Commands.Management.Storage.GetAzureStorageAccountCommand
2020-02-04T13:12:07.4851249Z ##[debug]
2020-02-04T13:12:07.4876156Z ##[debug]Script stack trace:
2020-02-04T13:12:07.4914114Z ##[debug]at Get-AzureStorageAccountResourceGroupName, D:\a\_tasks\AzureFileCopy_eb72cb01-a7e5-427b-a8a1-1b31ccac8a43\2.154.19\AzureUtilityGTE1.0.ps1: line 27
2020-02-04T13:12:07.4926798Z ##[debug]at Get-AzureStorageKeyFromARM, D:\a\_tasks\AzureFileCopy_eb72cb01-a7e5-427b-a8a1-1b31ccac8a43\2.154.19\AzureUtilityRest.ps1: line 28
2020-02-04T13:12:07.4942375Z ##[debug]at Get-StorageKey, D:\a\_tasks\AzureFileCopy_eb72cb01-a7e5-427b-a8a1-1b31ccac8a43\2.154.19\Utility.ps1: line 149
2020-02-04T13:12:07.4955473Z ##[debug]at <ScriptBlock>, D:\a\_tasks\AzureFileCopy_eb72cb01-a7e5-427b-a8a1-1b31ccac8a43\2.154.19\AzureFileCopy.ps1: line 101
2020-02-04T13:12:07.4968797Z ##[debug]at <ScriptBlock>, <No file>: line 1
2020-02-04T13:12:07.4982585Z ##[debug]at <ScriptBlock>, <No file>: line 22
2020-02-04T13:12:07.4996709Z ##[debug]at <ScriptBlock>, <No file>: line 18
2020-02-04T13:12:07.5010393Z ##[debug]at <ScriptBlock>, <No file>: line 1
2020-02-04T13:12:07.5033417Z ##[debug]Exception:
2020-02-04T13:12:07.5059409Z ##[debug]System.NullReferenceException: Object reference not set to an instance of an object.
2020-02-04T13:12:07.5073947Z ##[debug] at Microsoft.Azure.Commands.Management.Storage.Models.PSStorageAccount..ctor(StorageAccount storageAccount) in d:\workspace\powershell-sign\src\ResourceManager\Storage\Commands.Management.Storage\Models\PSStorageAccount.cs:line 27
2020-02-04T13:12:07.5086710Z ##[debug] at Microsoft.Azure.Commands.Management.Storage.Models.PSStorageAccount.Create(StorageAccount storageAccount, IStorageManagementClient client) in d:\workspace\powershell-sign\src\ResourceManager\Storage\Commands.Management.Storage\Models\PSStorageAccount.cs:line 87
2020-02-04T13:12:07.5104212Z ##[debug] at Microsoft.Azure.Commands.Management.Storage.StorageAccountBaseCmdlet.<>c__DisplayClass2.<WriteStorageAccountList>b__1(StorageAccount storageAccount) in d:\workspace\powershell-sign\src\ResourceManager\Storage\Commands.Management.Storage\StorageAccount\StorageAccountBaseCmdlet.cs:line 161
2020-02-04T13:12:07.5119770Z ##[debug] at Microsoft.WindowsAzure.Commands.Utilities.Common.GeneralUtilities.ForEach[T](IEnumerable`1 sequence, Action`1 action) in d:\workspace\powershell-sign\src\Common\Commands.Common\GeneralUtilities.cs:line 147
2020-02-04T13:12:07.5133721Z ##[debug] at Microsoft.Azure.Commands.Management.Storage.StorageAccountBaseCmdlet.WriteStorageAccountList(IEnumerable`1 storageAccounts) in d:\workspace\powershell-sign\src\ResourceManager\Storage\Commands.Management.Storage\StorageAccount\StorageAccountBaseCmdlet.cs:line 161
2020-02-04T13:12:07.5148324Z ##[debug] at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() in d:\workspace\powershell-sign\src\Common\Commands.Common\AzurePSCmdlet.cs:line 610
2020-02-04T13:12:07.5213129Z ##[error]Object reference not set to an instance of an object.
2020-02-04T13:12:07.5213434Z ##[debug]Processed: ##vso[task.logissue type=error]Object reference not set to an instance of an object.
2020-02-04T13:12:07.5222027Z ##[debug]Processed: ##vso[task.complete result=Failed]
2020-02-04T13:12:07.5808798Z ##[section]Finishing: AzureBlob File Copy
Is there any better debugging that I can enable for Azure DevOps tasks?
Hey Kevin if you want to get debug information in a release definition create a variable system.debug and set it to true. I just took a look at github and there is an open issue with the same error message for the v2 version of the task.
I would run it with debug, to see if its the same issue and then try the v3 version of the task.

Azure Runbook Authentication failed

I have created Azure run books under and Azure Automation account to process a large Azure Analysis services Tabular model.
When I attempt a full Tabular model process via PowerShell it times out at just after an hour of runtime.
Start: 8:47:50 AM
End: 9:48:25 AM
Command Start
Invoke-ProcessASDatabase -server "asazure://---" -DatabaseName "---" -RefreshType Full
Command End
Error Start
Invoke-ProcessASDatabase : Failed to save modifications to the server. Error returned: 'Timeout expired. The timeout
period elapsed prior to completion of the operation.. The exception was raised by the IDbCommand interface.
Technical Details:
RootActivityId: ---
Date (UTC): ---
The command has been canceled.. The exception was raised by the IDbCommand interface.
The command has been canceled.. The exception was raised by the IDbCommand interface.
The command has been canceled.. The exception was raised by the IDbCommand interface.
The command has been canceled.. The exception was raised by the IDbCommand interface.
The command has been canceled.. The exception was raised by the IDbCommand interface.
The command has been canceled.. The exception was raised by the IDbCommand interface.
'.
At line:3 char:1
Invoke-ProcessASDatabase -server "asazure://--- ...
+ CategoryInfo : InvalidArgument: (---:String) [Invoke-ProcessASDatabase],
OperationException
+ FullyQualifiedErrorId : Microsoft.AnalysisServices.PowerShell.Cmdlets.ProcessASDatabase
Error End
I then broke the process down to the partition level. The process partitions run successfully for about an hour as well processing over 100 partitions but then start getting authentication errors.
How can I get a full Tabular model process completed running under an Azure runbook?
Start: 8:59:50 PM
End: 10:06:28 PM
Command Start
Invoke-ProcessPartition -PartitionName "2018_Q4" -TableName "FACT_AR" -server "asazure://---" -Database "---" -RefreshType Full
Command End
Error Start
Invoke-ProcessPartition : Authentication failed.
Technical Details:
RootActivityId: ---
Date (UTC): ---
At line:104 char:1
Invoke-ProcessPartition -PartitionName "2018_Q4" -TableName "FACT_AR ...
+ CategoryInfo : NotSpecified: (:) [Invoke-ProcessPartition], ConnectionException
+ FullyQualifiedErrorId :
Microsoft.AnalysisServices.ConnectionException,Microsoft.AnalysisServices.PowerShell.Cmdlets.ProcessPartition
Error End
Welcome to Stack Overflow :)
Your issue looks similar to this -> Exceed 3 hours timeout Automation Runbook Azure. Please check it if the answers given in there helps to resolve your issue.
Also you may read about fair share from below Microsoft documentation.
https://learn.microsoft.com/en-us/azure/automation/automation-runbook-execution#fair-share
Hope this helps!!
It turned out the credential was somehow corrupted. Dropped the credential and re-created it and the job worked.

Set-AzureRmDiagnosticSetting : Exception type: CloudException, Message: Metric category 'AllMetrics' is not supported

I am getting below exception:
Exception type: CloudException, Message: Metric category 'AllMetrics'
is not supported.
Running Azure PowerShell command Set-AzureRmDiagnosticSetting for any Storage Account, same command works fine other resource type like Key Vault, Service Bus, Load Balancers etc.
Azure PowerShell command:
Set-AzureRmDiagnosticSetting -ResourceId $ResourceId -Enable $true
-RetentionInDays 365 -RetentionEnabled $true
Exception details:
Set-AzureRmDiagnosticSetting : Exception type: CloudException, Message: Metric category 'AllMetrics' is not
supported., Code: BadRequest, Status code:BadRequest, Reason phrase: Bad Request
At line:1 char:1
+ Set-AzureRmDiagnosticSetting -ResourceId '/subscriptions/c1ddf901-1db ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureRmDiagnosticSetting], PSInvalidOperationException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Insights.Diagnostics.SetAzureRmDiagnosticSettingCommand
Screenshot
Also tried specifying parameter -StorageAccountId $StorageAccountIdLogs with different Storage Account resource ID, still getting same exception.
Metric category 'AllMetrics' is not supported.
According to the error message, AllMetrics is not supported to Azure Storage Account.
To enable metrics of Storage Account, you could use Set-AzureStorageServiceMetricsProperty.
You could refer to my sample command, it works fine on my side.
C:\PS>$Context = New-AzureStorageContext -StorageAccountName <StorageAccountName > -StorageAccountKey <StorageAccountKey >
C:\PS>Set-AzureStorageServiceMetricsProperty -ServiceType Blob -MetricsType Hour -MetricsLevel Service -Pass Thru -RetentionDays 10 -Version 1.0 -Context $Context
For more details, refer to this article.

Resources