Is it possible to get the runbook name within the runbook environments?

117 Views Asked by At

I want to get the Azure runbook name within the environment sandbox of the runbook.

Is it possible to do that? Like, are there any predefined variables that we can get as in the case of Azure Pipelines?

I have checked a bit the documentation but I couldn't find anything related.

1

There are 1 best solutions below

6
Jahnavi On

AFAIK there is no predefined variables that you can use in automation to get the variable. After a workaround on this, I found a couple of approaches which are listed below.

Approach-1:

Using Get-AzAutomationVariable to retrieve the predefined variables by storing it in variables under shared resources of automation account blade as shown.

enter image description here

$Variable = (Get-AzAutomationVariable -AutomationAccountName "newauto" -Name "runbookname" -ResourceGroupName "<resourceGroup>").Name
write-output "variable name is $Variable."

enter image description here

Note: If you want to execute it in azure runbook, perform the same script and it will work as expected.

Approach-2:

Another one is using Start-AzAutomationRunbook. With this command, you can access the runbook by passing runbook name as a parameter in the automation script as given below.

$params = @{'runbookname' = 'new'}
Start-AzAutomationRunbook -AutomationAccountName "newauto" -Name "new" -ResourceGroupName "<resourcegroup>" -Parameters $params