> For the complete documentation index, see [llms.txt](https://docs.coherence.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coherence.io/2.3/manual/advanced-topics/team-workflows/continuous-integration-setup.md).

# Continuous integration best practices

## Baking

If your project contains/versions baked scripts, you should not need to include a bake step in your CI. However, if you decided not include baked files, or you are testing functionality that requires baking, you can trigger it in the following way.

Create a `Bake` method and call it from Unity via command line as a custom method.

```csharp
using Coherence.Editor;

public static class ContinuousIntegration
{
    public static void Bake() => BakeUtil.Bake();
}
```

<details>

<summary>bake.bat — for Windows</summary>

{% code overflow="wrap" %}

```bat
@echo off
"<unity-path>\Unity.exe" -projectPath "<project-path>" -batchmode -nographics -quit -executeMethod "ContinuousIntegration.Bake"
```

{% endcode %}

</details>

<details>

<summary>bake.sh — for Linux/macOS</summary>

{% code overflow="wrap" %}

```sh
#!/bin/sh
"<unity-path>/Unity" -projectPath "<project-path>" -batchmode -nographics -quit -executeMethod "ContinuousIntegration.Bake"
```

{% endcode %}

</details>

## Uploading a Schema to coherence Cloud

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:

1. Go to your [Online Dashboard](/2.3/hosting/coherence-cloud/online-dashboard.md).
2. Select the **Project** into which you want to upload the schema file.
3. You should now see the **Project ID** displayed on the right.
4. Next go to the **Settings** page of the project, and scroll down to the **Project Tokens** section to find the **Project Token**.

<figure><img src="/files/tTgzxE7V4yWzSsutH4NT" alt=""><figcaption><p><strong>Project ID</strong> in the Online Dashboard</p></figcaption></figure>

<figure><img src="/files/r3o5VCIxZzJcaptm5UmW" alt=""><figcaption><p><strong>Project Token</strong> in Project Settings</p></figcaption></figure>

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`.

```csharp
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);
    }
}
```

<details>

<summary><code>upload-schema.bat</code> — for Windows</summary>

{% code overflow="wrap" %}

```bat
@echo off

:: Set environment variables
set COHERENCE_PROJECT_ID="YOUR_PROJECT_ID"
set COHERENCE_PROJECT_TOKEN="YOUR_PROJECT_TOKEN"

:: Upload local schema using Unity
"<unity-path>\Unity.exe" -projectPath "<project-path>" -batchmode -nographics -quit -executeMethod "ContinuousIntegration.UploadSchema"
```

{% endcode %}

</details>

<details>

<summary><code>upload-schema.sh</code> — for Linux/macOS</summary>

{% code overflow="wrap" %}

```sh
#!/bin/sh

# Set environment variables
export COHERENCE_PROJECT_ID="YOUR_PROJECT_ID"
export COHERENCE_PROJECT_TOKEN="YOUR_PROJECT_TOKEN"

# Upload local schema using Unity
"<unity-path>/Unity" -projectPath "<project-path>" -batchmode -nographics -quit -executeMethod ContinuousIntegration.UploadSchema
```

{% endcode %}

</details>

## Replication Server

{% content-ref url="/pages/-MWdUUmqPNm2ny5UugFu" %}
[Replication server CLI](/2.3/manual/replication-server/command-line-interface.md)
{% endcontent-ref %}

## 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](/2.3/manual/simulation-server.md).

### 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.PrepareBuild**\
  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.BuildAndUpload**\
  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 BuildAndUpload method: **Project ID** and **Project Token**. See the [Uploading Schema](#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.BuildAndUpload`.

```csharp
using System;
using Coherence.Build;

public static class ContinuousIntegration
{
    public static void PrepareSimulator() => SimulatorBuildPipeline.PrepareBuild();

    public static void BuildAndUploadSimulator()
    {
        var projectId = Environment.GetEnvironmentVariable("COHERENCE_PROJECT_ID");
        var projectToken = Environment.GetEnvironmentVariable("COHERENCE_PROJECT_TOKEN");
        SimulatorBuildPipeline.BuildAndUpload(projectId, projectToken);
    }
}
```

The build will use the **Simulator Build Options** and and **Simulator Slug** that are configured in **coherence Hub > Simulators**.

<figure><img src="/files/V3zSr5GmReYV3H5MxdLr" alt=""><figcaption><p>The <strong>Simulators</strong> tab in the <strong>coherence Hub</strong> window</p></figcaption></figure>

<details>

<summary><code>upload-simulator.bat</code> — for Windows</summary>

{% code overflow="wrap" %}

```bat
@echo off

:: Set environment variables
set COHERENCE_PROJECT_ID="YOUR_PROJECT_ID"
set COHERENCE_PROJECT_TOKEN="YOUR_PROJECT_TOKEN"

:: Prepare Unity for creating a simulator build
"<unity-path>\Unity.exe" -projectPath "<project-path>" -batchmode -nographics -quit -executeMethod "ContinuousIntegration.PrepareSimulator"

:: Create and upload the simulator
"<unity-path>\Unity.exe" -projectPath "<project-path>" -batchmode -nographics -quit -executeMethod "ContinuousIntegration.BuildAndUploadSimulator"
```

{% endcode %}

</details>

<details>

<summary><code>upload-simulator.sh</code> — for Linux/macOS</summary>

{% code overflow="wrap" %}

```shellscript
#!/bin/sh

# Set environment variables
export COHERENCE_PROJECT_ID="YOUR_PROJECT_ID"
export COHERENCE_PROJECT_TOKEN="YOUR_PROJECT_TOKEN"

# Prepare Unity for creating a simulator build
"<unity-path>/Unity" -projectPath "<project-path>" -batchmode -nographics -quit -executeMethod "ContinuousIntegration.PrepareSimulator"

# Create and upload the simulator
"<unity-path>/Unity" -projectPath "<project-path>" -batchmode -nographics -quit -executeMethod "ContinuousIntegration.BuildAndUploadSimulator"
```

{% endcode %}

</details>

## Adding additional build steps

You can create your custom build steps by implementing Unity interfaces [IPreprocessBuildWithReport](https://docs.unity3d.com/ScriptReference/Build.IPreprocessBuildWithReport.html) and [IPostprocessBuildWithReport](https://docs.unity3d.com/ScriptReference/Build.IPostprocessBuildWithReport.html).&#x20;

## Game build pipeline

You can use the **UploadBuildToCoherence** API to upload your game builds to the **coherence Cloud** from the command line. Windows, WebGL, Linux and macOS builds are supported, via the **UploadWindowsBuild**, **UploadWebGlBuild**, **UploadLinuxBuild** and **UploadMacOsBuild** methods respectively.

You will need to pass three arguments to UploadBuildToCoherence's build methods: path to the game build, **Project ID** and **Project Token**. See the [Uploading Schema](#uploading-schema) section for details on how to acquire the latter two.

You can provide the arguments as environment variables in your continuous integration setup, and create a `UploadGameBuilds` method which can be called from Unity via command line as a custom method, and handles retrieving the environment variables and passing them to UploadBuildToCoherence's build methods.

{% code overflow="wrap" %}

```csharp
using System;
using System.IO;
using Coherence.Editor;

public static class ContinuousIntegration
{
    public static void UploadGameBuilds()
    {
        var projectId = Environment.GetEnvironmentVariable("COHERENCE_PROJECT_ID");
        var projectToken = Environment.GetEnvironmentVariable("COHERENCE_PROJECT_TOKEN");

        var windowsBuildPath = Environment.GetEnvironmentVariable("BUILD_PATH_WINDOWS");
        if (Exists(windowsBuildPath))
        {
            UploadBuildToCoherence.UploadWindowsBuild(windowsBuildPath, projectId, projectToken);
        }

        var webGlBuildPath = Environment.GetEnvironmentVariable("BUILD_PATH_WEBGL");
        if (Exists(webGlBuildPath))
        {
            UploadBuildToCoherence.UploadWebGlBuild(webGlBuildPath, projectId, projectToken);
        }

        var linuxBuildPath = Environment.GetEnvironmentVariable("BUILD_PATH_LINUX");
        if (Exists(linuxBuildPath))
        {
            UploadBuildToCoherence.UploadLinuxBuild(linuxBuildPath, projectId, projectToken);
        }

        var macOsBuildPath = Environment.GetEnvironmentVariable("BUILD_PATH_MACOS");
        if (Exists(macOsBuildPath))
        {
            UploadBuildToCoherence.UploadMacOsBuild(macOsBuildPath, projectId, projectToken);
        }
    }

    static bool Exists(string path) => Directory.Exists(path) || File.Exists(path);
}
```

{% endcode %}

<details>

<summary><code>upload-game-builds.bat</code> — for Windows</summary>

{% code overflow="wrap" %}

```bat
@echo off

:: Set environment variables
set COHERENCE_PROJECT_ID="YOUR_PROJECT_ID"
set COHERENCE_PROJECT_TOKEN="YOUR_PROJECT_TOKEN"
set BUILD_PATH_WINDOWS="<project-path>/Builds/Windows"
set BUILD_PATH_WEBGL="<project-path>/Builds/Web"
set BUILD_PATH_LINUX="<project-path>/Builds/Linux"
set BUILD_PATH_MACOS="<project-path>/Builds/macOS"

:: Upload the builds
"<unity-path>\Unity.exe" -projectPath "<project-path>" -batchmode -nographics -quit -executeMethod "ContinuousIntegration.UploadGameBuilds"
```

{% endcode %}

</details>

<details>

<summary><code>upload-game-builds.sh</code> — for Linux/macOS</summary>

{% code overflow="wrap" %}

```shellscript
#!/bin/sh

# Set environment variables
export COHERENCE_PROJECT_ID="YOUR_PROJECT_ID"
export COHERENCE_PROJECT_TOKEN="YOUR_PROJECT_TOKEN"
export BUILD_PATH_WINDOWS="<project-path>/Builds/Windows"
export BUILD_PATH_WEBGL="<project-path>/Builds/Web"
export BUILD_PATH_LINUX="<project-path>/Builds/Linux"
export BUILD_PATH_MACOS="<project-path>/Builds/macOS"

# Upload the builds
"<unity-path>/Unity" -projectPath "<project-path>" -batchmode -nographics -quit -executeMethod "ContinuousIntegration.UploadGameBuilds"
```

{% endcode %}

</details>

After executing your script, if everything was configured properly, you should see the uploaded builds appear in your [Online Dashboard](/2.3/hosting/coherence-cloud/online-dashboard.md) under the project you targeted, in the **Schemas & Builds > Game Builds** section.

<figure><img src="/files/8zIsOtkREjm3FsaYO4bL" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.coherence.io/2.3/manual/advanced-topics/team-workflows/continuous-integration-setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
