Prerequisite
A quick guide how to set up Azure and Azure DevOps (VSTS) to automate the build process of your game made in Unity3D. this guide assumes that you have the following:
- Azure Subscription
- Azure DevOps Organization
- A Unity3D game project
- GIT knowledge
- Basic Azure and Azure DevOps (VSTS) knowledge
Setup build agent in Azure
- Login to your subscription in the Azure Portal (https://portal.azure.com).
- Deploy a new virtual machine and select a VisualStudio image (I use VS 2017 latest on windows 10 N), but remembert that W10 only is available on MSDN subscriptions.
- Configure the VM to be accessible via RDP (but remember to remove this endpoint when you are done.
- Wait for the VM to deploy and start.
- Connect to the VM using RDP
- On the VM install Unity3D, start it and login. This is required at least if you are using the free license.
- Login to Azure DevOps (former VSTS) and configure a new build agent. (Self hosted agent)
- Configure the agent
- Wait for the agent to become active in the Azure DevOps portal
Prepare your Unity project
- Open the project
- Create a new folder under assets named editor
- Create a new script (C#)
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;public class GameBuilder
{
static void build()
{
// Place all your scenes here
string[] scenes = {“Assets/scenes/SampleScene.unity”};
string pathToDeploy = “bin/windwos64/exeName.exe”;
BuildPipeline.BuildPlayer(scenes, pathToDeploy, BuildTarget.StandaloneWindows64, BuildOptions.None);
}
} - Change the scenes to include your scenes and change the pathToDeploy to a suitable name.
Configure Azure DevOps
- Create a new project
- Use git to push your game code to the newly created project.
- Create a new blank build definition.
- Add a powershell step and use this inline script
$project = “\”
$arguments = @(
“-quit”,
“-batchmode”,
“-logFile stdout.log”,
“-projectPath $project”,
“-executeMethod GameBuilder.build”
“-username $(unityusername)”,
“-password $(unitypassword)”
)
$processinfo = Start-Process -FilePath “C:\Program Files\Unity\Editor\Unity.exe” -ArgumentList $arguments -PassThru
Wait-Process -Id $processinfo.Id - Add two new pipeline variables
- unityusername – your username to unity
- unitypassword – your password to unity (remeber to check the lock icon to make your password variable a secret)
- Finnaly add a publish artifact step and change the Path to publish to bin (pathToDeploy in your GameBuilder class)
- Save and queue
The artifacts of this build will be the the win64 version of the Unity player. You can browse and download the artifacts from the portal, to verify the build.
The next step is to release the build, but that’s another story đ