This is 5 part blog series, on how to “Cost Optimization for On-demand Private Build Server for SharePoint”. Although I specifically write this for SharePoint’s build server, however the concept and ideas is also applicable for anyone looking for optimizing their cost running private CI/CD (Continuous Integration/Continuous Delivery) in Visual Studio online. The series in these articles are:
- Part 1, Introduction to Visual Studio Online Build and Release Agent
- Part 2, Cost Analysis and Optimizing Cost
- Part 3, Step-by-Step Creation Private Build Server for SharePoint
- Part 4, Azure Automation Service
- Part 5, Integrates Azure Automation Service in Build Pipeline
In Part 3, we have prepared private build server in Azure using B2S VM size. The VM was created using Visual Studio Enterprise 2017 template. After provisioning, we installed SharePoint 2016, NodeJS and some additional software. At the end of the steps, we install build/release agent in the server and connect to VSTS tenant using PAT (Personal Access Token).
Azure Automation Service
In Part 2, I have shown that based on our utilization we only need very small fraction of VM online hours in a month. However, the build agent must be online to be able to accept build/release job; otherwise it will be queued and it won’t be delivered on time.
I can schedule auto-shutdown the VM at 07:00 PM daily, and assign someone to start the VM when he/she starts the computer in the morning. Probably using PowerShell script, to starts Azure-VM.
Then, this is where Azure Automation becomes very useful. Azure Automation delivers a cloud-based automation and configuration that run consistently across Azure and non-Azure environment. It offers many automation capabilities such as:
- Process Automation, through graphical, PowerShell and Python runbooks
- Configuration Management, collect inventory, track changes, configure desired state etc.
- Update Management, access compliance, schedule update installation etc.
- Role-based access control, where controls to account can be provided to Automation operator without giving authoring capabilities
Read complete capabilities of Azure Automation here (https://docs.microsoft.com/en-us/azure/automation/automation-intro)
In this case, instead of asking one of the team to start VM in the morning – and let the computer shutdown in the evening. I am going to use Azure Automation to schedule start and stop of the VM.
I follow Quickstarts here – https://docs.microsoft.com/en-us/azure/automation/automation-quickstart-create-account , to create my Azure Automation service. Once the service has been provisioned, then I perform following actions
- Add Azure VM in Inventory
- Click Inventory
- Click Add Azure VM
- Add Runbooks, to start VM daily at 07:00 AM. (I don’t change the existing shutdown schedule at 07:00 PM)
- Click Runbooks
- Click Browse gallery
- Search for “Start Azure V2 VMs”
- Click Import
- In the next dialog, just type the name “Start-MyAzureVM”. And click OK
- In the “Start-MyAzureVM” overview page, click Edit
- In the “Edit Graphical Runbook”, click Publish. (Note you can change the logic using graphical editor)
- After publishing, then the “Schedule” will be active. In “Start-MyAzureVM” overview page, click “Schedule”
- In the Schedule Runbook, I schedule to execute the runbook , daily at 07:00 AM. Then click Create.
- In the Configure parameters and run settings, I define the ResourceGroupName, VMName so it matched with the private build VM name.
Now our private build server will be online between 07:00 AM – 07:00 PM daily. In cost perspective, our monthly cost is now half of the original to about USD 23.73 / month.