This repository was archived by the owner on Mar 28, 2026. It is now read-only.
forked from RoryDungan/Unity-CI-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunity-build.ps1
More file actions
47 lines (39 loc) · 1.89 KB
/
Copy pathunity-build.ps1
File metadata and controls
47 lines (39 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function Check-Env ($variableName, $message) {
if (![System.Environment]::GetEnvironmentVariable($variableName)) {
Write-Host "$variableName environment variable not set!"
Write-Host $message
Exit 1
}
}
Check-Env 'BUILDS_DIR' 'This should be set to the directory to save builds in.'
Check-Env 'BUILD_METHOD' 'This should be set to the C# method to invoke to create the build.'
Check-Env 'BUILD_TARGET' 'This should be set to the platform to build for.'
# Set project source to the full path to the directory containing this script
$src = $PSScriptRoot
$outdir = $Env:BUILDS_DIR
# Create temporary file for the Unity log.
# We need this because if multiple editor instances are open we can't rely on the contents of the default Editor.log
# containing output just from this instance.
$logfile = [System.IO.Path]::GetTempFileName()
# Path to Unity - change to match your install location
$unity = 'C:\Program Files\Unity\Hub\Editor\2018.3.7f1\Editor\Unity.exe'
Write-Host "Building to $OUTDIR"
Write-Host "Build started:" (Get-Date).ToString()
$process = $null
try {
$unityArgs = "-nographics -quit -batchmode -buildTarget $Env:BUILD_TARGET -projectPath `"$src`" -logFile `"$logFile`" -executeMethod $Env:BUILD_METHOD -buildPath `"$outdir`""
$process = Start-Process -FilePath "$unity" -ArgumentList $unityArgs -PassThru
Wait-Process -Id $process.Id
# Write log output to standard output. TODO: Can we tail the file and output in real time as it's being written to?
Get-Content $logfile
}
finally {
# Kill Unity if this script was killed. This makes sure the build actually stops if we cancel the job in Jenkins.
if ($process -ne $null -And -Not $process.HasExited) {
Stop-Process $process.Id
}
# Remove temporary log file
Remove-Item $logfile
}
# Exit script with Unity exit code
Exit $process.ExitCode