Skip to content

Instantly share code, notes, and snippets.

@hach-que
Created April 7, 2020 02:29
Show Gist options
  • Save hach-que/8ecbcce30caa49e4018290306a2574f7 to your computer and use it in GitHub Desktop.
Save hach-que/8ecbcce30caa49e4018290306a2574f7 to your computer and use it in GitHub Desktop.
Building Unreal Engine games on GitLab
variables:
GIT_SUBMODULE_STRATEGY: recursive
master:
stage: build
tags:
- redpoint-games-windows
script:
- .\Build.ps1 -ProjectName "MinuteOfMayhem" -EngineVersion "4.24" -DiscordApplicationId "" -DiscordBotToken "" -DiscordReleaseBranch ""
- Write-Output "Finalising..."
- exit $LastExitCode
only:
- master

.gitlab-ci.yml should go in your project root; make sure the tags matches whatever tag you gave the GitLab runner when you set it up: https://docs.gitlab.com/runner/install/

Replace the parameters to the Build.ps1 call with your own stuff as appropriate.

#!/usr/bin/env pwsh
#Requires -Version 5
param([string] $ProjectName, [string] $EngineVersion = "4.24", [string]$DiscordApplicationId, [string]$DiscordBotToken, [string]$DiscordReleaseBranch)
$process = $null
trap {
if ($process -ne $null -and -not $process.HasExited) {
$process.Kill();
}
Write-Error $_
exit 1
}
$EnginePath = "$env:PROGRAMFILES\Epic Games\UE_$EngineVersion"
if (Test-Path "HKLM:\SOFTWARE\EpicGames\Unreal Engine\$EngineVersion") {
$EnginePath = (Get-ItemProperty -Path "HKLM:\SOFTWARE\EpicGames\Unreal Engine\$EngineVersion" -Name "InstalledDirectory").InstalledDirectory;
}
Write-Host ">> INFO: Using Unreal Engine located at '$EnginePath'"
function Wait-For-Process-Exit($Process) {
while (!$Process.HasExited) {
Start-Sleep -Seconds 1
}
}
$ErrorActionPreference = "Stop"
$cwd = Get-Location
Write-Host ">> STEP: Update Git submodules"
git submodule update --init --recursive
Write-Host ">> STEP: Generate version number"
if (Test-Path Output) {
Remove-Item -Recurse -Force Output
}
mkdir Output
Write-Output ("v" + $ENV:BUILD_NUMBER + " built at " + ((Get-Date).ToString())) | Out-File -Encoding ASCII Content\\Data\\BuildSignature.txt
Write-Host ">> STEP: Remove previous build artifacts"
if (Test-Path .\Binaries\Win64) {
Remove-Item -Force -Recurse .\Binaries\Win64
}
if (Test-Path .\Intermediate) {
Remove-Item -Force -Recurse .\Intermediate
}
foreach ($Item in Get-ChildItem -Path .\Plugins) {
if (Test-Path "$($Item.FullName)\Binaries") {
Remove-Item -Force -Recurse "$($Item.FullName)\Binaries"
}
if (Test-Path "$($Item.FullName)\Intermediate") {
Remove-Item -Force -Recurse "$($Item.FullName)\Intermediate"
}
}
if (!(Test-Path $env:USERPROFILE\.dispatch)) {
New-Item -ItemType Directory -Path $env:USERPROFILE\.dispatch
}
if (!(Test-Path $env:USERPROFILE\.dispatch\credentials.json) -or (Get-Content -Raw $env:USERPROFILE\.dispatch\credentials.json).Contains("BotCredentials")) {
Write-Host ">> STEP: Authenticate Discord"
Set-Content -Path $env:USERPROFILE\.dispatch\credentials.json -Value @"
{
"BotCredentials": {
"application_id": "$DiscordApplicationId",
"token": "$DiscordBotToken"
}
}
"@
}
Write-Host ">> STEP: Build editor"
Set-Content -Value "" -Path "$PSScriptRoot\Empty.txt"
$process = Start-Process `
-FilePath "$EnginePath\Engine\Binaries\DotNET\UnrealBuildTool.exe" `
-ArgumentList @(
"Development",
"Win64",
"-Project=`"$PSScriptRoot\$ProjectName.uproject`"",
"-TargetType=Editor",
"-Progress",
"-NoHotReloadFromIDE"
) `
-NoNewWindow `
-PassThru
$handle = $process.Handle
Wait-For-Process-Exit -Process $process
if ($process.ExitCode -ne 0) {
Write-Error -Message ("General pre-build failed (got exit code: " + $process.ExitCode + ")!")
exit 1
}
Write-Host ">> STEP: Static lighting bake"
$ContentPath = "$PSScriptRoot\Content\Levels".Replace("\", "/")
$process = Start-Process `
-FilePath "$EnginePath\Engine\Binaries\Win64\UE4Editor-Cmd.exe" `
-ArgumentList @(
"$PSScriptRoot\$ProjectName.uproject",
"-run=resavepackages",
"-buildtexturestreaming",
"-buildlighting",
"-MapsOnly",
"-ProjectOnly",
"-AllowCommandletRendering",
"-SkipSkinVerify",
"-PACKAGEFOLDER=$ContentPath",
"-stdout",
"-crashforuat",
"-unattended"
) `
-NoNewWindow `
-WorkingDirectory "$PSScriptRoot\Content" `
-PassThru
$handle = $process.Handle
Wait-For-Process-Exit -Process $process
if ($process.ExitCode -ne 0) {
Write-Output $process.ExitCode
Write-Error -Message "Lighting build failed!"
exit 1
}
Write-Host ">> STEP: Build game (Development)"
$process = Start-Process `
-FilePath "$EnginePath\Engine\Build\BatchFiles\RunUAT.bat" `
-ArgumentList @(
"BuildCookRun",
"-project=$PSScriptRoot\MinuteOfMayhem.uproject",
"-noP4",
"-platform=Win64",
"-clientconfig=Development",
"-serverconfig=Development",
"-cook",
"-allmaps",
"-build",
"-stage",
"-pak",
"-archive",
"-archivedirectory=$PSScriptRoot\Output",
"-unattended"
) `
-NoNewWindow `
-PassThru `
-RedirectStandardInput "$PSScriptRoot\Empty.txt"
$handle = $process.Handle
Wait-For-Process-Exit -Process $process
if ($process.ExitCode -ne 0) {
Write-Error -Message "General build failed!"
exit 1
}
Write-Host ">> STEP: Copy Redist to output folder"
Copy-Item -Force "$cwd\Extras\UE4PrereqSetup_x64.exe" "$cwd\Saved\StagedBuilds\WindowsNoEditor\UE4PrereqSetup_x64.exe"
Write-Host ">> STEP: Push to Discord"
$process = Start-Process `
-FilePath "C:\Discord\dispatch.exe" `
-ArgumentList @(
"build",
"push",
"-p",
"$DiscordReleaseBranch",
"config.json",
"."
) `
-NoNewWindow `
-PassThru
$handle = $process.Handle
Wait-For-Process-Exit -Process $process
if ($process.ExitCode -ne 0) {
Write-Error -Message "Discord push failed!"
exit 1
}
Write-Host ">> STEP: All done!"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment