more
This commit is contained in:
+32
-12
@@ -95,28 +95,48 @@ try {
|
|||||||
|
|
||||||
Write-Host "Using Unity method: $method"
|
Write-Host "Using Unity method: $method"
|
||||||
|
|
||||||
# -----------------------------
|
Write-Host "===================================================================="
|
||||||
# Run Unity build
|
Write-Host "===================== Starting Unity Build ========================="
|
||||||
# -----------------------------
|
Write-Host "===================================================================="
|
||||||
|
|
||||||
|
# 1. Define arguments cleanly using an array
|
||||||
|
$logFile = "$PWD/unity_build.log"
|
||||||
$unityArgs = @(
|
$unityArgs = @(
|
||||||
"-batchmode",
|
"-batchmode",
|
||||||
"-nographics",
|
"-nographics",
|
||||||
"-quit",
|
"-quit",
|
||||||
"-projectPath", "$PWD",
|
"-projectPath", "$PWD",
|
||||||
"-executeMethod", "$method",
|
"-executeMethod", "$method",
|
||||||
"-logFile", "$PWD/unity_batch_build.log" # CRITICAL: Captures what goes wrong
|
"-logFile", "$logFile"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Execute using the array
|
# 2. Start the Unity process in the background
|
||||||
& $unityEditorPath @unityArgs
|
$process = Start-Process -FilePath $unityEditorPath -ArgumentList $unityArgs -PassThru -NoNewWindow
|
||||||
|
|
||||||
$exitCode = $LASTEXITCODE
|
# 3. Wait for the log file to be created by Unity
|
||||||
|
while (!(Test-Path $logFile) -and !$process.HasExited) {
|
||||||
|
Start-Sleep -Milliseconds 100
|
||||||
|
}
|
||||||
|
|
||||||
# -----------------------------
|
# 4. Stream the log live into the TeamCity console
|
||||||
# Validate result
|
if (Test-Path $logFile) {
|
||||||
# -----------------------------
|
# Get-Content -Wait streams the file until the process kills it
|
||||||
if ($exitCode -ne 0) {
|
$logJob = Start-Job -ScriptBlock { Get-Content $using:logFile -Wait }
|
||||||
throw "Unity build failed ($Target). Exit code: $exitCode"
|
|
||||||
|
# Wait for Unity to completely finish building
|
||||||
|
$process.WaitForExit()
|
||||||
|
|
||||||
|
# Stop streaming and clean up
|
||||||
|
Stop-Job $logJob
|
||||||
|
Receive-Job $logJob
|
||||||
|
Remove-Job $logJob
|
||||||
|
Remove-Item $logFile -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
# 5. Bubble up the exit code so TeamCity catches errors
|
||||||
|
if ($process.ExitCode -ne 0) {
|
||||||
|
Write-Error "Unity build failed with exit code $($process.ExitCode)"
|
||||||
|
exit $process.ExitCode
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "===================================="
|
Write-Host "===================================="
|
||||||
|
|||||||
Reference in New Issue
Block a user