Powershell Runbooks allow you to get the Job ID with $PSPrivateMetadata.JobId.Guid
How do we get it if the runbook is Python?
Powershell Runbooks allow you to get the Job ID with $PSPrivateMetadata.JobId.Guid
How do we get it if the runbook is Python?
2
Answers
According to the API documentation, you can create a Python Runbook using
runbook = azure.mgmt.automation.models.Runbook(<options>)
, then access therunbook.id
property.Source: https://learn.microsoft.com/en-us/python/api/azure-mgmt-automation/azure.mgmt.automation.models.runbook?view=azure-python
This is what you need.
To retrieve the Azure Automation Runbook Job Id in a Python Runbook, you can use the
AutomationJobId
environment variable that is automatically provided by Azure Automation. Here’s how you can access the Runbook Job Id in a Python script within an Azure Automation Runbook:In the code snippet, I used the
os.environ.get()
method to retrieve the value of theAutomationJobId
environment variable, which contains the unique identifier of the current job being executed in Azure Automation. You can then use thisrunbook_job_id
variable to track or log the job id as needed within your Python script.