Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.26k stars 3.86k forks source link

Start-AzAutomationRunbook swallows error returned from service #19823

Open robpukdf opened 2 years ago

robpukdf commented 2 years ago

Description

I am trying to call an Azure Automation Hybrid Worker Runbook from another Azure Automation Runbook, but I keep receiving a null reference error. To start, I was just trying to call one Runbook from another:

Parent:

Start-AzAutomationRunbook -AutomationAccountName "XXX" -Name "ChildToCallFromParent" -ResourceGroupName "YYY" -Parameters @{"userDataDiffs"="testString"}

Child:

param ( [string] $userDataDiffs )

Write-Output $userDataDiffs

Output:

Start-AzAutomationRunbook : Object reference not set to an instance of an object. At line:29 char:1 + Start-AzAutomationRunbook -AutomationAccountName "XXX" ... +

Anyone have any guidance on this please?

Script or Debug output

No response

Environment data

No response

Module versions

No response

Error output

No response

robpukdf commented 2 years ago

I managed to get it to work using this code:

$adminCredential = Get-AutomationPSCredential -Name 'test@test.com' $creds = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $adminCredential.UserName, $adminCredential.Password $conn = Connect-AzAccount -Credential $creds

$azureContext = Set-AzContext -Tenant -Subscription

Start-AzAutomationRunbook -AutomationAccountName "XXX" -Name "ChildToCallFromParent" -ResourceGroupName "YYY" -DefaultProfile $azureContext -RunOn "DEV-HYB-WORKERS" -Wait -Parameters @{"userDataDiffs"="testString"}

dingmeng-xue commented 2 years ago

@robpukdf , Azure PowerShell establishes multiple contexts if user can access to multiple subscriptions. According to your script and error, it seems target automation account is not in default subscription. You need to either switch context using Set-AzContext or just login to target subscription via Connect-AzAccount -Tenant <> -Subscription <>

The error message is client side problem. I believe service returns 404 error. It should not be swallowed. I include owner team to fix it.

ghost commented 2 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jaspkaur28.

Issue Details
### Description I am trying to call an Azure Automation Hybrid Worker Runbook from another Azure Automation Runbook, but I keep receiving a null reference error. To start, I was just trying to call one Runbook from another: Parent: Start-AzAutomationRunbook -AutomationAccountName "XXX" -Name "ChildToCallFromParent" -ResourceGroupName "YYY" -Parameters @{"userDataDiffs"="testString"} Child: param ( [string] $userDataDiffs ) Write-Output $userDataDiffs Output: Start-AzAutomationRunbook : Object reference not set to an instance of an object. At line:29 char:1 + Start-AzAutomationRunbook -AutomationAccountName "XXX" ... + Anyone have any guidance on this please? ### Script or Debug output _No response_ ### Environment data _No response_ ### Module versions _No response_ ### Error output _No response_
Author: robpukdf
Assignees: -
Labels: `Automation`, `Service Attention`, `bug`, `customer-reported`, `good first issue`
Milestone: -