If you need to to share values between Azure runbooks or parameterise them, Automation Variables may be just the thing you need.
Essentially these are exactly what you might expect – variables which you define and can use within Azure. The variables can be updated via Powershell scripts, manually via the Azure portal and of course by runbooks.
The first thing to do is to define the variable. To do this go to the Azure portal and go into the Automation section. Following this navigate to the assets section, click new and select ‘Add Setting’
Select ‘Add Variable’
Fill in the relevant details for the variable. Note the variable type can be changed programmatically later if this is required.
Set a default value for the variable if it’s required and if the variable contains sensitive information you can also select for it to be encrypted.
To access the variable from the Powershell script the syntax used is like this:
Get-AutomationVariable -Name ‘VariableName’
So for example, in order to access the value of a variable called “ETLProcessStatus” and assign this to a variable named $CurrentRunStatus you would do the following:
$CurrentRunStatus = Get-AutomationVariable -Name “ETLProcessStatus”
In case you forget the syntax for retrieving or updating the value of the variables there is a nice feature where it will write the basic syntax out for you.
Click insert at the bottom of the ribbon and then ‘Setting’
Following this you can select from the following options and template commands will be inserted into the script.
In a blog which will be coming shortly, I will detail how I use this variable and some other techniques in order to assist in running a scalable cloud ETL solution.
Please get in touch if you would like to know more