Continuous Integration
Tips and trips for setting up Continuous Integration (CI) for your projects
Tips for automated building
Continuous Integration means that any changes to the project are merged frequently into the main branch, and automation (especially of testing) is used to ensure quality. The main benefits of Continuous Integration (henceforth CI) are that it makes software development easier, faster, and less risky for developers. Building your Game Client with CI and automated testing might require coherence setup.
For automated delivery of your project changes and testing it in CI, you can take the following steps to make sure coherence is set up appropriately in your project before building a standalone Client.
Baking
You need to bake your code before building to ensure that your local schema file is up-to-date. This can be done by executing the BakeUtil.Bake method.
You can create a Bake
method and call it from Unity via command line as a custom method.
using Coherence.Editor;
public static class ContinuousIntegration
{
public static void Bake() => BakeUtil.Bake();
}
Example batch script
Here is an example batch script that could be saved as bake.bat
and executed on a Windows machine to perform baking:
@echo off
:: Bake using Unity
"C:\Program Files\Unity\Hub\Editor\6000.1.2f3\Editor\Unity.exe" -projectPath "C:\Unity Projects\My Game" -batchmode -nographics -quit -executeMethod ContinuousIntegration.Bake
Example shell script
Here is an example shell script that could be saved as bake.sh
and executed on an Linux or OSX machine to perform baking:
#!/bin/bash
# Bake using Unity
"/home/user/Unity/Hub/Editor/6000.1.2f3/Editor/Unity" -projectPath "/home/user/Unity Projects/My Game" -batchmode -nographics -quit -executeMethod ContinuousIntegration.Bake
Uploading Schema
If your project works using a Replication Server running in coherence Cloud, you will also need to upload your local schema file. This can be done by executing the Schemas.Upload method.
You will need to pass two arguments to the Schemas.Upload method: Project ID and Project Token. You can find these out by following the below steps:
Go to your Online Dashboard.
Select the Project into which you want to upload the schema file.
You should now see the Project ID displayed on the right.
Next go to the Settings page of the project, and scroll down to the Project Tokens section to find the Project Token.


You can provide the Project ID
and Project Token
as environment variables in your continuous integration setup, and create an UploadSchema
method which can be called from Unity via command line as a custom method, and handles retrieving the environment variables and passing them to Schemas.Upload
.
using System;
using Coherence.Editor.Portal;
public static class ContinuousIntegration
{
public static void UploadSchema()
{
var projectId = Environment.GetEnvironmentVariable("COHERENCE_PROJECT_ID");
var projectToken = Environment.GetEnvironmentVariable("COHERENCE_PROJECT_TOKEN");
Schemas.Upload(projectId, projectToken);
}
}
Example batch script
Here is an example batch script that could be saved as upload-schema.bat
and executed on a Windows machine to upload your local schema:
@echo off
:: Set environment variables
set COHERENCE_PROJECT_TOKEN=<YOUR_PROJECT_TOKEN>
set COHERENCE_PROJECT_ID=<YOUR_PROJECT_ID>
:: Upload local schema using Unity
"C:\Program Files\Unity\Hub\Editor\6000.1.2f3\Editor\Unity.exe" -projectPath "C:\Unity Projects\My Game" -batchmode -nographics -quit -executeMethod ContinuousIntegration.UploadSchema
Example shell script
Here is an example shell script that could be saved as upload-schema.sh
and executed on an Linux or OSX machine to upload your local schema:
#!/bin/bash
# Set environment variables
export COHERENCE_PROJECT_TOKEN=<YOUR_PROJECT_TOKEN>
export COHERENCE_PROJECT_ID=<YOUR_PROJECT_ID>
# Upload local schema using Unity
"/home/user/Unity/Hub/Editor/6000.1.2f3/Editor/Unity" -projectPath "/home/user/Unity Projects/My Game" -batchmode -nographics -quit -executeMethod ContinuousIntegration.UploadSchema
Running the Replication Server
To start the Replication Server in CI you can use the scripts generated in the 📁 Library/coherence
folder: run-replication-server-rooms
and run-replication-server-worlds
.
Simulator build pipeline
You can use the Simulator Build Pipeline public API to build and upload your Simulator builds to the coherence Cloud from the command line. If you wish to learn more about Simulators, check out the dedicated section.
Building and uploading to the Cloud
There are two methods you will need to call, in order, to build and upload a Simulator build successfully:
SimulatorBuildPipeline.PrepareHeadlessBuild This method will add the COHERENCE_SIMULATOR scripting symbol, will set the build sub target to Server (for Unity 2021) and it will change the platform to Linux. It is necessary to perform these steps in an isolated Unity execution, because in batch mode, there is no editor loop that will make sure your assemblies are reloaded with the changes.
SimulatorBuildPipeline.BuildHeadlessLinuxClientAsync This method will build the Unity Client and upload it to your selected organization and project.
You will need to pass two arguments to the BuildHeadlessLinuxClientAsync method: Project ID and Project Token. See the Uploading Schema section for details on how to acquire them.
You can provide the Project ID and Project Token as environment variables in your continuous integration setup, and create a BuildAndUploadSimulator
method which can be called from Unity via command line as a custom method, and handles retrieving the environment variables and passing them to SimulatorBuildPipeline.BuildHeadlessLinuxClientAsync
.
using System;
using Coherence.Build;
public static class ContinuousIntegration
{
public static void PrepareSimulator() => SimulatorBuildPipeline.PrepareHeadlessBuild();
public static void BuildAndUploadSimulator()
{
var projectId = Environment.GetEnvironmentVariable("COHERENCE_PROJECT_ID");
var projectToken = Environment.GetEnvironmentVariable("COHERENCE_PROJECT_TOKEN");
SimulatorBuildPipeline.BuildHeadlessLinuxClientAsync(projectId, projectToken);
}
}
The build will use the Simulator Build Options and and Simulator Slug that are configured in coherence Hub > Simulators.

Example batch script
Here is an example batch script that could be saved as upload-schema.bat
and executed on a Windows machine to upload your local schema:
@echo off
:: Set environment variables
set COHERENCE_PROJECT_TOKEN=<YOUR_PROJECT_TOKEN>
set COHERENCE_PROJECT_ID=<YOUR_PROJECT_ID>
:: Prepare Unity for creating a simulator build
"C:\Program Files\Unity\Hub\Editor\6000.1.2f3\Editor\Unity.exe" -projectPath "C:\Unity Projects\My Game" -batchmode -nographics -quit -executeMethod ContinuousIntegration.PrepareSimulator
:: Create and upload the simulator
"C:\Program Files\Unity\Hub\Editor\6000.1.2f3\Editor\Unity.exe" -projectPath "C:\Unity Projects\My Game" -batchmode -nographics -quit -executeMethod ContinuousIntegration.BuildAndUploadSimulator
Example shell script
Here is an example shell script that could be saved as upload-schema.sh
and executed on an Linux or OSX machine to upload your local schema:
#!/bin/bash
# Set environment variables
export COHERENCE_PROJECT_TOKEN=<YOUR_PROJECT_TOKEN>
export COHERENCE_PROJECT_ID=<YOUR_PROJECT_ID>
# Prepare Unity for creating a simulator build
"/home/user/Unity/Hub/Editor/6000.1.2f3/Editor/Unity" -projectPath "/home/user/Unity Projects/My Game" -batchmode -nographics -quit -executeMethod ContinuousIntegration.PrepareSimulator
# Create and upload the simulator
"/home/user/Unity/Hub/Editor/6000.1.2f3/Editor/Unity" -projectPath "/home/user/Unity Projects/My Game" -batchmode -nographics -quit -executeMethod ContinuousIntegration.BuildAndUploadSimulator
Customizing your Simulator builds
You can create your custom build steps by implementing Unity interfaces IPreprocessBuildWithReport and IPostprocessBuildWithReport. In order to verify that the build being created is a Simulator, you can check for the SimulatorBuildPipeline.IsBuildingSimulator boolean.
Last updated
Was this helpful?