Get in touch with us!

CI Pipeline for Unity3D projects in Azure DevOps

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

  1. Login to your subscription in the Azure Portal (https://portal.azure.com).
  2. 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.
  3. Configure the VM to be accessible via RDP (but remember to remove this endpoint when you are done.
  4. Wait for the VM to deploy and start.
  5. Connect to the VM using RDP
  6. On the VM install Unity3D, start it and login. This is required at least if you are using the free license.
  7. Login to Azure DevOps (former VSTS) and configure a new build agent. (Self hosted agent)
  8. Configure the agent
  9. Wait for the agent to become active in the Azure DevOps portal

Prepare your Unity project

  1. Open the project
  2. Create a new folder under assets named editor
  3. 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);
    }
    }
  4. Change the scenes to include your scenes and change the pathToDeploy to a suitable name.

Configure Azure DevOps

  1. Create a new project
  2. Use git to push your game code to the newly created project.
  3. Create a new blank build definition.
  4. 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
  5. 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)
  6. Finnaly add a publish artifact step and change the Path to publish to bin (pathToDeploy in your GameBuilder class)
  7. 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 🙂

Submit a Comment

Your email address will not be published. Required fields are marked *