28 Nov 2016 | Azure
In a previous post I setup a build agent in a private pipeline - hosted within a Azure Virtual Machine (VM). In this one, I try to minimize the uptime of the VM by making it run only during work hours - I require it to start automatically first thing in the morning and then turn itself off at the close of business. In order to achieve this I make use of the Azure Automation feature.
Let's start off by logging into our Azure account and creating a new Automation Account
entry.
Provide the required details:
Name
- Name for the automation account.Subscription
- Azure subscription for this account.Resource Group
- Create or select an existing resource group from the list. Location
- Select an available region from the list.Create Azure Run As account
- Select Yes
.Click the Create
button to start provisioning the automation account.
Once done, navigate to it's blade via the resource groups and click on the Runbooks
widget.
The runbook gallery had a couple of really good graphical runbooks that suited my purposes - the Start Azure V2 VMs
and Stop Azure V2 VMs
.
Click on the Browse Gallery
button, select the Start Azure V2 VMs
graphical runbook and then click OK
to confirm the selection.
Inspect the flow and click the Import
button when ready.
Navigate into the newly added runbook and click the Edit
button. Make any alterations if required and click the Publish
button.
Back on the runbook blade, click on Schedules
widget and then click on the Add a schedule
button.
Click on the Link a schedule to your runbook
and then create a new schedule. Provide the time and recurrence for the script execution. Read more about scheduling here.
Next, select Configure parameters and run settings
and provide a virtual machine name or resource group which would start on execution.
Click the ok
button once done. You should get a confirmation that the schedule is linked to a runbook.
That's it. The runbook would execute at the pre-defined time.
Repeat the above steps again to create a stop script using the Stop Azure V2 VMs
graphical runbook.