Continuous integration is best defined as the process of constantly merging development artifacts produced or modified by different members of a team into a central shared repository. This task of collating changes becomes more and more complex as the size of the team grows. Ensuring the stability of the central repository becomes a serious challenge in such cases.
A solution to this problem is to validate every merge with automated builds and automated testing. Modern code management platforms like Visual Studio Team Services (VSTS) offers built-in tools to perform these operations. Visual Studio Team Services (VSTS) is a hosted service offering from Microsoft which bundles a collection of Dev Ops services for application developers.
The requirement for a Continuous Integration workflow is important for HoloLens applications considering the agility of the development process. In a typical engagement, designers and developers will work on parallel streams sharing scripts and artifacts which constitute a scene. Having an automated process in place to validate every check-in to the central repository can add tremendous value to the quality of the application. In this blog, we will walk through the process of setting up a Continuous Integration workflow for a HoloLens application using VSTS build and release tools.
A HoloLens application will have multiple application layers. The development starts with creating the game world using Unity and then proceeds to wiring up backend scripts and services using Visual Studio. To build a HoloLens application package, we need to first build the front-end game world with the Unity compiler and then, the back-end with the visual studio compiler. The following diagram illustrates the build pipeline:
In the following sections, we will walk through the process of setting up the infrastructure for building a HoloLens application package using VSTS.
Build agent setup
VSTS uses build agents to perform the task of compiling an application on the central repository. These build agents can either be Microsoft hosted agents, which is available as a service in VSTS or they can be custom-deployed services managed by you. HoloLens application will require custom build agents as they run custom build tasks for compiling the Unity application. Following are the steps for creating a build agent to run the tasks required for building a HoloLens application:
1. Provision hosting environment for the build agent
The first step in this process is to provision a machine to run the build agent as a service. I’d recommend using an Azure Virtual Machine hosted within an Azure DevTest Lab for this purpose. The DevTest Lab comes with built-in features for managing start up and shut down schedules for the virtual machines which are very effective in controlling the consumption cost. Following are the steps for setting up the host environment for the build agent in Azure.
- Login to the Azure portal and create a new instance of DevTest Lab
- Add a Virtual machine to the Lab.
- Pick an image with Visual Studio 2017 pre-installed.
- Choose the hardware with a high number of CPUs and IOPS as the agents are heavy on disks and compute. I’d advice a D8S_V3 machine for a team of approximately 15 developers.
- Select the PowerShell artifacts to be added to the Virtual machine
- Provision the Virtual Machine and remote desktop into it.
2. Create authorization token
Build agent will require an authorized channel to communicate with the build server which in our case is the VSTS service. Following are the steps to generate a token:
- On VSTS portal, navigate to the security screen using the profile menu
- Create a personal access token for the agent to authorize to the server. Ensure that you have selected ‘Agent pools (read, manage) in the authorized scope.
- Note the generated token. This will be used to configure the agent the build host virtual machine.
3. Installing and configuring the agent
Once the token is generated we are now ready to configure the VSTS agent. Following are the steps
- Remote desktop into the build host virtual machine on Azure
- Open the VSTS portal on a browser and navigate to the ‘Agent Queue’ screen. (https://.visualstudio.com/Utopia/_admin/_AgentQueue)
- Click on ‘Download Agent’ button
- Click on the ‘Download’ button to download the installer onto the disk of your VM. Choose the default download location.
- Follow the steps listed in the previous step to configure the agent using PowerShell commands. Detailed instructions can be found at the below link:
- Once configures, the agent should appear on the agent list within the selected pool.
This completes the build environment setup. We can now configure a build definition for our HoloLens application.
Creating the build definition involves queuing up a sequence of activities to be performed during a build. In our case, this includes the following steps.
- Performing Unity build
- Restoring NuGet packages
- Performing Visual Studio build
Following are the steps to be performed:
- Login to the VSTS portal and navigate to the marketplace.
- Search for the ‘HoloLens Unity Build’ component and install it. Make sure that you are selecting the right VSTS project while installing the component.
- Navigate to Builds on the VSTS portal and click on the ‘New’ button under ‘Build Definitions’
- Select an empty template
- Add the following dev tasks
- HoloLens Unity Build
- Visual Studio Build
- Select the Unity Project folder to configure the build task
- Configure the Nuget build task to restore the packages.
- Configure the Visual Studio build task by selecting the solution path, platform, and configuration.
- Navigate to the ‘Triggers’ tab and Enable the build to be triggered for every check-in.
You should now see a build being fired for every merge into the repository. The whole build process for an empty HoloLens application can take anywhere between four to six minutes on an average.
To summarise, in this blog, we learned about the build pipeline for a HoloLens application. We also explored the build agent set up and build definition required to enable continuous integration for a HoloLens application.