Introducing the Unreal Engine Plugin for JetBrains TeamCity
Tags: teamcity, gamedev, unreal, cicd
Published: 2024-05-14 14:40:51

<!-- wp:paragraph -->
<p>TeamCity is a popular choice in game development for several reasons, including its support for Perforce, its ability to be installed on premises, and its numerous configuration options.
<br><br>
In addition to its main application as a general-purpose CI/CD solution, we’re also striving to bring dedicated support for various<a href="https://www.jetbrains.com/teamcity/integrations/build-tools/"> build tools</a>, too. Having already provided a Unity plugin for several years, we're now excited to officially introduce our <a href="https://plugins.jetbrains.com/plugin/22679-unreal-engine-support">Unreal Engine Support plugin</a>!</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>We’ve been in close contact with several of our game development customers throughout the development of this new plugin to ensure it meets the needs of DevOps teams working on real-world Unreal Engine projects.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Setting up a proper build pipeline for an Unreal Engine game can be a daunting task, especially for those with limited experience of the platform’s unique peculiarities. In this blog post, we'll walk you through a basic setup, while showcasing the plugin's features and demonstrating advanced capabilities such as distributed BuildGraph support.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":473421,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://blog.jetbrains.com/wp-content/uploads/2024/05/sample-build-pipeline.png" alt="" class="wp-image-473421"/><figcaption class="wp-element-caption">A sample build pipeline generated by the new Unreal Engine plugin</figcaption></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2 class="wp-block-heading"><strong>Key features</strong></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Here's a quick overview of what you can expect from this version of the plugin:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>A dedicated runner tailored for most common use cases (BuildCookRun, BuildGraph, and automation tests).</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Build distribution based on your BuildGraph description.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>On-the-fly automation test reporting.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Automatic discovery of Unreal Engine installations on the build machines.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Compatibility with the latest 5.x versions of Unreal Engine, plus support for 4.x.</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2 class="wp-block-heading"><strong>The demo</strong></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In this demo, we’ll be setting up a pipeline for two starter games shipped with Unreal:<em> Cropout</em> and <em>Lyra</em>. We’ll use AWS infrastructure (EC2 and FSx for OpenZFS) for build agents and TeamCity Cloud with the Unreal Engine plugin installed.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>We’ll look at two scenarios: when the engine is already installed on an agent and when it’s built from source along with the game. At the moment, TeamCity Cloud doesn’t offer agents with the preinstalled Unreal Engine, but you can always add your own<a href="https://www.jetbrains.com/help/teamcity/cloud/install-and-start-teamcity-agents.html"> self-hosted agent</a> with all the required SDKs. This is the approach we’ll stick to in this blog post.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading"><strong>Building </strong><strong><em>Cropout</em></strong><strong> with BuildCookRun</strong></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Building an Unreal project usually involves<a href="https://dev.epicgames.com/documentation/en-us/unreal-engine/build-operations-cooking-packaging-deploying-and-running-projects-in-unreal-engine"> many steps</a>, such as:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>Compilation for the target platforms in the specified configurations.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Asset cooking (converting all of the assets into ones that can be read on the target platforms).</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Packaging of the project into a proper distribution format.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>And many more.</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Then, of course, there’s the testing!</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To begin with, let’s start with a simple scenario and run all of these stages sequentially on a single machine utilizing the standard BuildCookRun command.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For this scenario, we’ll use the latest vanilla Unreal Engine version available at the moment of writing, installed from EGL (Epic Games Launcher).</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>After successfully connecting the agent to our TeamCity Cloud server, we can see it in the <em>Agents</em> tab.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":473444,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://blog.jetbrains.com/wp-content/uploads/2024/05/teamcity-cloud-agents-pool.png" alt="" class="wp-image-473444"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>At this point, I’d like to take a moment to briefly explore some of the agent’s properties.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":473456,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://blog.jetbrains.com/wp-content/uploads/2024/05/agents-properties.png" alt="" class="wp-image-473456"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Here, looking at the picture above, we see that the agent discovered the engine and its version (we have more than one on our machine, as you can see). Keep a note of this information, as we’ll need it later for a build step configuration.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Nowadays, the common approach is to store all your configs as code under source control (i.e. configuration as code). In TeamCity, you can do this using <a href="https://www.jetbrains.com/teamcity/features/configuration-as-code/" data-type="link" data-id="https://www.jetbrains.com/teamcity/features/configuration-as-code/">Kotlin DSL</a>. Of course, you can also go with the traditional UI configuration, but today, we’ll use the first approach (due to the popularity of YAML and the fact that it has become a de-facto standard, we’ve added it as a part of our recent release of<a href="/?p=457320"> TeamCity Pipelines –</a> check it out if you haven’t already).</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The Kotlin DSL configuration for building<em> Cropout </em>in TeamCity looks like this:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>unrealEngine {
    engineDetectionMode = automatic {
        identifier = "5.4"
    }
    command = buildCookRun {
        project = "cropout/CropoutSampleProject.uproject"
        buildConfiguration = standaloneGame {
            configurations = "Development+Shipping"
            platforms = "Mac"
        }
        cook = cookConfiguration {
            maps = "Village+MainMenu"
            cultures = "en"
            unversionedContent = true
        }
        stage = stageConfiguration {
            directory = "./staged"
        }
        archive = archiveConfiguration {
            directory = "./archived"
        }
        pak = true
        compressed = true
        prerequisites = true
    }
    additionalArguments = "-utf8output -buildmachine -unattended -noP4 -nosplash -stdout -NoCodeSign"
}
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>All of the settings are pretty self-descriptive, but there are a couple worth paying closer attention to:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<code>engine detection mode</code><br><br>Here, we can specify either “automatic” or “manual”. The former assumes you already have the engine installed on your agent and registered in the system.
<br>Let me take this opportunity to clarify what “registered” means: Whenever you install the Unreal Engine from EGL or build it from source, it writes to certain files on the target machine (or registry in the case of Windows). More information on that can be found<a href="https://dev.epicgames.com/documentation/en-us/unreal-engine/installed-build-reference-guide-for-unreal-engine#registeringaninstalledbuild"> here</a>.<br><br>This is essentially what the automatic detection mode is for. We read those files and publish identifiers as agent properties, so you can use them later to select the proper agent for your build.<br><br>The “manual” mode allows you to set the exact path to the Unreal Engine root folder, which might be useful when you build from source. We'll touch on that later.<br>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<code>build configuration</code><br><br>By adjusting this parameter, we can specify the type of build we're creating, whether it's a standalone game, client, server, or both client and server components.<br><br>Depending on the selected value, the plugin will apply <code>-client</code>, <code>-server</code>, <code>-noserver </code>flags and manage <code>-clientconfig</code>, <code>-serverconfig</code>, <code>-config</code>, <code>-targetplatform</code>, and <code>-servertargetplatform</code> parameters accordingly.
<!-- /wp:list-item -->
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>So far, so good. Now, it’s time to add some automation tests and run the final pipeline.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>unrealEngine {
    engineDetectionMode = automatic {
        identifier = "5.4"
    }
    command = runAutomation {
        project = "cropout/CropoutSampleProject.uproject"
        execCommand = runTests {
            tests = """
                StartsWith:JsonConfig
                Input.Triggers.Released
            """.trimIndent()
        }
        nullRHI = true
    }
    additionalArguments = "-utf8output -buildmachine -unattended -noP4 -nosplash -stdout -NoCodeSign"
}
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>As you may know, when working with the Unreal Engine Automation Framework, tests are usually executed using one of the following automation “subcommands”:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li><code>RunAll</code> – this is a pretty straightforward command that has the ability to run all required tests.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><code>RunFilter </code>– with this command, tests tagged with one of the specified filters (which includes such values as <code>Engine</code>, <code>Stress</code>, <code>Smoke</code>, etc.) can be executed.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><code>RunTests</code> – this is the most versatile command, as it allows you to specify the list of tests to run (including prefix filters with <code>StartsWith</code>, run group filters, and simple substring matches).</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>We tried to preserve the same wording in Kotlin DSL to keep it familiar for Unreal folks.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It's also worth mentioning that the plugin parses the results of the tests on the fly and presents them in a nicely formatted manner native to TeamCity.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":473479,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://blog.jetbrains.com/wp-content/uploads/2024/05/teamcity-test-results.png" alt="" class="wp-image-473479"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Here’s what the result of the build looks like:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":473490,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://blog.jetbrains.com/wp-content/uploads/2024/05/build-results-teamcity.png" alt="" class="wp-image-473490"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Below, we can see the game binaries published to the <a href="https://www.jetbrains.com/help/teamcity/configuring-artifacts-storage.html">Artifacts Storage</a>. By default, artifacts are published to <a href="https://www.jetbrains.com/help/teamcity/configuring-artifacts-storage.html#Built-in+Artifacts+Storage">built-in storage</a>; however, TeamCity also supports various<a href="https://www.jetbrains.com/help/teamcity/configuring-artifacts-storage.html#external-artifacts-storage"> external storage</a> options. In the context of the cloud, it makes sense to configure publishing to S3.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":473501,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://blog.jetbrains.com/wp-content/uploads/2024/05/external-storage-options-teamcity.png" alt="" class="wp-image-473501"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>The final configuration in the UI would then look like this:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":473512,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://blog.jetbrains.com/wp-content/uploads/2024/05/ui-configuration-option-step1.png" alt="" class="wp-image-473512"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>And here’s the step with the test run:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":473523,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://blog.jetbrains.com/wp-content/uploads/2024/05/ui-configuration-option-step2.png" alt="" class="wp-image-473523"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>All the settings are disabled since we've enabled Kotlin DSL configuration and disabled editing it in the UI.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading"><strong>Building </strong><strong><em>Lyra</em></strong><strong> with BuildGraph</strong></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>We're slowly moving towards a more complex example with Lyra. Since it's a multiplayer game, let's build a Linux server (as we know that everything high-performance should be run on Linux!), along with Windows and Linux game clients.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In the previous example, we ran all the steps sequentially on a single machine. Usually, this takes a significant amount of time. But there’s a better way, and it's called BuildGraph. This is Unreal's method for describing your build declaratively (or almost) as a set of tasks with dependencies among them. The different parts of the graph can then be executed together or split across different machines. The latter approach allows you to dramatically speed up the entire build process, especially for a big and complex project.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The nice thing about BuildGraph is it manages all of the intermediate artifacts between jobs automatically. All you need is shared storage. While building <em>Lyra</em>, we’ll be using this shared storage for two purposes: sharing data between nodes within a single build and maintaining a shared derived data cache (DDC).</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>As we mentioned earlier, we’ll also build the engine from the source. There are multiple reasons why you might want to do that, but in our specific case, it’s because there’s no way to build a Linux server from the engine installed from EGL (at least at the time this post was written). This is due to the lack of files and SDKs provided with this particular engine version.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Okay, that’s enough preamble – let’s get to grips with the code.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The structure of the project and corresponding streams in Perforce look like this (we assume that you already have the Unreal Engine source code from Epic’s Perforce):</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":473534,"width":"424px","height":"auto","aspectRatio":"0.7458729364682342","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full is-resized"><img src="https://blog.jetbrains.com/wp-content/uploads/2024/05/lyra-perforce.png" alt="" class="wp-image-473534" style="aspect-ratio:0.7458729364682342;width:424px;height:auto"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Here’s the excerpt of the BuildGraph XML script that we’ll use for our build. This particular part of the script shows how we’ll build the editor along with the tools required for the compilation. It also contains a few tests, too. In our simple example, these are hardcoded. In a real-world scenario, you’d likely pass a list of tests to the script and employ more complicated logic.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>...
&lt;!-- Editors --&gt;
  &lt;ForEach Name="Platform" Values="$(EditorPlatforms)" Separator="+"&gt;
    &lt;Property Name="Compiler" Value="$(AgentPrefixCompile)$(Platform)" /&gt;

    &lt;Agent Name="Build Editor and tools $(Platform)" Type="$(Compiler)"&gt;
		    
		    ...

      &lt;Property Name="ExtraToolCompileArguments" Value="$(ExtraToolCompileArguments) -architecture=arm64" If="'$(Platform)' == 'Mac'" /&gt;
      
      &lt;Node Name="$(ToolsNodeName) $(Platform)" Requires="Setup Toolchain $(Platform)" Produces="#$(Platform)ToolBinaries"&gt;
        &lt;Compile Target="CrashReportClient" Platform="$(Platform)" Configuration="Shipping" Arguments="$(ExtraToolCompileArguments)" Tag="#$(Platform)ToolBinaries"/&gt;
        &lt;Compile Target="CrashReportClientEditor" Platform="$(Platform)" Configuration="Shipping" Arguments="$(ExtraToolCompileArguments)" Tag="#$(Platform)ToolBinaries"/&gt;
        &lt;Compile Target="ShaderCompileWorker" Platform="$(Platform)" Configuration="Development" Arguments="$(ExtraToolCompileArguments)" Tag="#$(Platform)ToolBinaries"/&gt;
        &lt;Compile Target="UnrealLightmass" Platform="$(Platform)" Configuration="Development" Tag="#$(Platform)ToolBinaries"/&gt;
        &lt;Compile Target="InterchangeWorker" Platform="$(Platform)" Configuration="Development" Arguments="$(ExtraToolCompileArguments)" Tag="#$(Platform)ToolBinaries"/&gt;
        &lt;Compile Target="UnrealPak" Platform="$(Platform)" Configuration="Development" Arguments="$(ExtraToolCompileArguments)" Tag="#$(Platform)ToolBinaries"/&gt;
        &lt;Compile Target="BootstrapPackagedGame" Platform="$(Platform)" Configuration="Shipping" Arguments="$(ExtraToolCompileArguments)" Tag="#$(Platform)ToolBinaries" If="'$(Platform)' == 'Win64'"/&gt;
      &lt;/Node&gt;
      
      ...
      
      &lt;Node Name="$(EditorNodeName) $(Platform)" Requires="$(ToolsNodeName) $(Platform)" Produces="#$(Platform)EditorBinaries"&gt;
        &lt;Compile Target="$(ProjectName)Editor" Project="$(UProject)" Platform="$(Platform)" Configuration="Development" Arguments="$(ExtraEditorCompileArguments)" Tag="#$(Platform)EditorBinaries"/&gt;
      &lt;/Node&gt;

			&lt;Property Name="AutomationTestsNodeName" Value="Run Tests $(Platform)" /&gt;
      &lt;Node Name="$(AutomationTestsNodeName)" Requires="$(EditorNodeName) $(Platform)"&gt;
        &lt;Property Name="TestArgs" Value="-Project=$(UProject) -NullRHI -Deterministic" /&gt;
        &lt;Property Name="TestArgs" Value="$(TestArgs) -Test=UE.EditorAutomation -RunTest=&amp;quot;StartsWith:Input&amp;quot;" /&gt;
        &lt;Property Name="TestArgs" Value="$(TestArgs) -Build=Editor -UseEditor" /&gt;
        &lt;Command Name="RunUnreal" Arguments="$(TestArgs)" /&gt;
      &lt;/Node&gt;
    &lt;/Agent&gt;

    &lt;Property Name="BuildNodes" Value="$(BuildNodes);$(EditorNodeName) $(Platform);$(AutomationTestsNodeName);" /&gt;
  &lt;/ForEach&gt;
  
  ...
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>The full syntax is described in full on Epic’s website. Here, what we’re essentially doing is iterating over the list of platforms passed to the script via an option <code>EditorPlatforms</code> and building the <em>Editor</em> for each. One interesting feature of this part of the code is the <code>Type</code> property of the agent node.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>&lt;Agent ... Type=""&gt; 
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>See this table from <a href="https://dev.epicgames.com/documentation/en-us/unreal-engine/buildgraph-script-elements-reference-for-unreal-engine#agent" data-type="link" data-id="https://dev.epicgames.com/documentation/en-us/unreal-engine/buildgraph-script-elements-reference-for-unreal-engine#agent">the documentation</a>:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":473552,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://blog.jetbrains.com/wp-content/uploads/2024/05/Screenshot-2024-05-14-at-14.18.51.png" alt="" class="wp-image-473552"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>So, in order to run a set of tasks on a particular agent, you can manipulate this field. At the time of writing, to make everything work, this part requires a little configuration of your build agents. Namely, you should define two properties in the<a href="https://www.jetbrains.com/help/teamcity/configure-agent-installation.html"> agent’s configuration file</a>:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li><code>unreal-engine.build-graph.agent.type</code>: This could be any value (or a list of values separated by <strong>;</strong>). The corresponding set of tasks will then be run only on an agent with at least one match.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li><code>unreal-engine.build-graph.agent.shared-dir</code>: As discussed earlier, in order to run distributed BuildGraph builds, we need a shared storage location. With this property, we set a path to this storage location on a specific agent.</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>This is what our setup for our EC2 build agents looks like:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>For Linux:</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:code -->
<pre class="wp-block-code"><code>unreal-engine.build-graph.agent.type = CompileLinux;CookLinux;Linux
unreal-engine.build-graph.agent.shared-dir = /mnt/agent-shared-dir/intermediate
</code></pre>
<!-- /wp:code -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>And for Windows (for some reason, mounting the folder as a separate drive caused one of the Windows system calls to fail, so we opted for a network share in the configuration):</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:code -->
<pre class="wp-block-code"><code>unreal-engine.build-graph.agent.type = CompileWin64;CookWin64;Win64
unreal-engine.build-graph.agent.shared-dir = \\\\fs-040b8d6dab476baf1.fsx.eu-west-1.amazonaws.com\\fsx\\
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>For real-world scenarios, it might make sense to differentiate between agents that perform cooking and those that perform compilation and ensure they have the appropriate specs.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Let’s quickly take a look at what the processes of compilation, cooking and packaging of the game look like. In our script, we’ve separated the logic for building a client and building a server (as they differ in terms of passed flags):</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>&lt;ForEach Name="Platform" Values="$(ClientPlatforms)" Separator="+"&gt;
    &lt;!-- COMPILATION --&gt;
    &lt;Property Name="Compiler" Value="$(AgentPrefixCompile)$(Platform)" /&gt;
    &lt;Agent Name="Compile $(Platform) Client" Type="$(Compiler)"&gt;

      &lt;Property Name="CompileNodeName" Value="Compile $(Platform) Client" /&gt;  
      &lt;Node Name="$(CompileNodeName)" Requires="$(ToolsNodeName) $(Platform)" Produces="#$(Platform) Client Binaries"&gt;
        &lt;ForEach Name="TargetConfiguration" Values="$(TargetConfigurations)" Separator="+"&gt;    
          &lt;Compile Target="$(ProjectName)Client" Project="$(UProject)" Platform="$(Platform)" Configuration="$(TargetConfiguration)" Arguments="$(ExtraProjectCompileArguments)" /&gt;
        &lt;/ForEach&gt;
      &lt;/Node&gt;

      &lt;Property Name="BuildNodes" Value="$(BuildNodes);$(CompileNodeName);" /&gt;
    &lt;/Agent&gt;

    &lt;!-- COOKING --&gt;
    &lt;Property Name="Cooker" Value="$(AgentPrefixCook)$(Platform)" /&gt;

    &lt;Property Name="CookPlatformNodeName" Value="Cook $(Platform) Client" /&gt;
    &lt;Agent Name="Cook $(Platform) Client" Type="$(Cooker)"&gt;
      &lt;Property Name="CookPlatform" Value="$(Platform)" /&gt;
      &lt;Property Name="CookPlatform" Value="Windows" If="'$(Platform)' == 'Win64'" /&gt;

      &lt;Node Name="$(CookPlatformNodeName)" Requires="$(EditorNodeName) $(Platform)" Produces="#Cook $(Platform) Client Complete"&gt;
        &lt;Cook Project="$(UProject)" Platform="$(CookPlatform)Client"/&gt;
      &lt;/Node&gt;
    &lt;/Agent&gt;

    &lt;Property Name="BuildNodes" Value="$(BuildNodes);$(CookPlatformNodeName);" /&gt;

    &lt;!-- PACKAGING --&gt;
    &lt;Agent Name="Package $(Platform) Client" Type="$(Platform)"&gt;
      &lt;Property Name="BCRArgs" Value="-Project='$(UProject)' -Platform=$(Platform) -NoCodeSign -Client" /&gt;

        &lt;!-- Stage --&gt;
      &lt;Node Name="Stage $(Platform) Client" Requires="Compile $(Platform) Client;Cook $(Platform) Client"&gt;
        &lt;ForEach Name="TargetConfiguration" Values="$(TargetConfigurations)" Separator="+"&gt;
          &lt;Command Name="BuildCookRun" Arguments="$(BCRArgs) -Configuration=$(TargetConfiguration) -SkipBuild -SkipCook -Stage -Pak" /&gt;
        &lt;/ForEach&gt;
      &lt;/Node&gt;

      &lt;!-- Package --&gt;
      &lt;Node Name="Package $(Platform) Client" Requires="Stage $(Platform) Client"&gt;
        &lt;ForEach Name="TargetConfiguration" Values="$(TargetConfigurations)" Separator="+"&gt;    
          &lt;Command Name="BuildCookRun" Arguments="$(BCRArgs) -Configuration=$(TargetConfiguration) -SkipBuild -SkipCook -SkipStage -Package" /&gt;
        &lt;/ForEach&gt;
      &lt;/Node&gt;

      &lt;!-- Publish (Packages) --&gt;
      &lt;Node Name="Archive $(Platform) Client" Requires="Package $(Platform) Client"&gt;
        &lt;ForEach Name="TargetConfiguration" Values="$(TargetConfigurations)" Separator="+"&gt;    
          &lt;Command Name="BuildCookRun" Arguments="$(BCRArgs) -Configuration=$(TargetConfiguration) -SkipBuild -SkipCook -SkipStage -SkipPak -SkipPackage -Archive" /&gt;
        &lt;/ForEach&gt;
      &lt;/Node&gt;

      &lt;Node Name="Publish $(Platform) Client" Requires="Archive $(Platform) Client"&gt;
        &lt;Property Name="PublishPlatform" Value="$(Platform)" /&gt;
        &lt;Property Name="PublishPlatform" Value="Windows" If="'$(Platform)' == 'Win64'" /&gt;
        &lt;Log Message="##teamcity&#91;publishArtifacts 'game/ArchivedBuilds/$(PublishPlatform)Client=&gt;$(PublishPlatform)Client.zip']" /&gt;
      &lt;/Node&gt;
    &lt;/Agent&gt;

    &lt;Property Name="BuildNodes" Value="$(BuildNodes);Archive $(Platform) Client;Publish $(Platform) Client" /&gt;
  &lt;/ForEach&gt;
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>The script is pretty self-explanatory. We iterate over the list of platforms on which we want our client to run, which is again passed as an option. We compile for each of the platforms, cook the assets, and finally package everything. As the last step of the packaging process, we use a service message to publish the built client as a TeamCity build artifact.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>As you might have noticed, in this part of the script, we have three agents representing three stages of the build process (compilation, cooking, and packaging). The compilation requires tools belonging to the editor, but not the editor itself:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>&lt;Node Name="$(CompileNodeName)" Requires="$(ToolsNodeName) $(Platform)" Produces="#$(Platform) Client Binaries"&gt;
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Meanwhile, the cooking process requires the actual editor:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>&lt;Node Name="$(CookPlatformNodeName)" Requires="$(EditorNodeName) $(Platform)" Produces="#Cook $(Platform) Client Complete"&gt;
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>And since there is no dependency between these two processes, they can run in parallel on different machines (if you have enough machines available). This simple example demonstrates the power of using BuildGraph: You simply describe pieces of work that share dependencies, and then they run simultaneously.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In the interest of brevity, we won’t show the rest of the script that includes the server part, as it looks very similar to what we just described, with only the set of flags differing.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Finally, we've reached the part with the plugin configuration in TeamCity. Since most of the work is described in the BuildGraph XML script, the DSL configuration is fairly brief:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>params {
    param("env.UE_SharedDataCachePath", "/mnt/agent-shared-dir/ddc")
    param("env.UE-SharedDataCachePath", "\\\\fs-040b8d6dab476baf1.fsx.eu-west-1.amazonaws.com\\fsx\\ddc")
}

steps {
    unrealEngine {
        id = "Unreal_Engine"
        name = "Build"
        engineDetectionMode = manual {
            rootDir = "engine"
        }
        command = buildGraph {
            script = "game/BuildProject.xml"
            targetNode = "BuildProject"
            options = """
                ProjectPath=%teamcity.build.checkoutDir%/game
                ProjectName=Lyra
                ClientPlatforms=Linux+Win64
                ServerPlatforms=Linux
                EditorPlatforms=Linux+Win64
                TargetConfigurations=Shipping
            """.trimIndent()
            mode = UnrealEngine.BuildGraphMode.Distributed
        }
        additionalArguments = "-utf8output -buildmachine -unattended -noP4 -nosplash -stdout -NoCodeSign"
    }
}
</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Here, we specify that we’d like to run the given BuildGraph script in distributed mode. Nevertheless, there’s always an option to run all the nodes sequentially on a single machine if we want to. We’ve also specified<a href="https://dev.epicgames.com/documentation/en-us/unreal-engine/using-derived-data-cache-in-unreal-engine#howtosetupasharedddc"> a couple of environment variables</a> that are required for the engine to enable the usage of a shared DDC. Those folders should already be mounted to the agents connected to TeamCity.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Now, we can pass the following list of three platform options for our game: <code>ClientPlatforms</code>, <code>ServerPlatforms</code>, and <code>EditorPlatforms</code>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In the UI, it looks like this:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":473563,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://blog.jetbrains.com/wp-content/uploads/2024/05/build-step-unreal-engine.png" alt="" class="wp-image-473563"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>When we launch the build, we get this build chain:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":473574,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://blog.jetbrains.com/wp-content/uploads/2024/05/build-chain-unreal-engine.png" alt="" class="wp-image-473574"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>So, as we can see, the plugin has transformed the graph into a proper TeamCity build chain.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>We can check the published artifacts on the corresponding tab of the specific build. Here's what it looks like for the Linux server:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":473596,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full"><img src="https://blog.jetbrains.com/wp-content/uploads/2024/05/linux-server-unreal-engine-teamcity-1.png" alt="" class="wp-image-473596"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Before finishing up, we'd like to emphasize some important points to bear in mind:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>In order for the distribution process of BuildGraph to work, your build configuration should contain exactly one active build step.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Currently, the plugin does not manage the retention period of the produced artifacts in the shared storage in any way. It's your responsibility to set it up properly.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Examples in this blog post are by no means production-ready. Your real-world scenarios will likely be more complex. However, they could serve as a good starting point.</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2 class="wp-block-heading"><strong>Try it out!</strong></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You can get the demo code shown in this blog post from the<a href="https://github.com/lesley29/unreal-teamcity-demo"> GitHub repository</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you’d like to try out the Unreal Engine plugin for TeamCity, you can download it from <a href="https://plugins.jetbrains.com/plugin/22679-unreal-engine-support">JetBrains Marketplace</a> and install it on a TeamCity On-Premises server.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For TeamCity Cloud users, the Unreal Engine plugin has been pre-installed, allowing you to use it simply by adding an Unreal Engine build step. As a reminder, TeamCity Cloud agents don’t have Unreal Engine pre-installed, so you will need to use a self-hosted agent to run an Unreal Engine build.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>An important note for those who have been using a preview version of the plugin (any version that starts with 0.x.x): Please take into account that your existing configurations will be broken, as we have made changes and redesigned several features in the 1.0.0 version. You may need to recreate those configurations using the new version of the plugin.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading"><strong>What’s next?</strong></h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>First off, we’re looking forward to receiving your feedback. Please feel free to get in touch by submitting a ticket via our <a href="https://youtrack.jetbrains.com/issues/TW">issue tracker</a> or by commenting on this blog post.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>There are also some ideas we have in mind for further work, including:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><!-- wp:list-item -->
<li>Providing a more in-depth build log analysis.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Including integration with UnrealGameSync (UGS), with features like build status publication and the potential provision of an out-of-the-box metadata server.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Adding detection of the SDKs available on build machines, possibly using Turnkey.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Looking into Gauntlet Automation Framework and what we can do there.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Looking into how we can leverage recent advancements in the build process introduced by Epic Games, namely, checking out Unreal Build Accelerator (UBA) and coordinating it on the agents from TeamCity.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Open-sourcing the plugin. We believe that this will increase transparency and allow for the creation of a better plugin overall. Furthermore, going open source can be a lot of fun.</li>
<!-- /wp:list-item -->

<!-- wp:list-item -->
<li>Anything else you can think of! If you have an idea of something that would be nice to have, please feel free to reach out via any of the channels we mentioned above or simply by leaving a comment on this blog post.</li>
<!-- /wp:list-item --></ul>
<!-- /wp:list -->