This commit is contained in:
2026-06-23 00:58:55 +09:30
parent 2556e275bd
commit 02886a3834
+32 -12
View File
@@ -95,28 +95,48 @@ try {
Write-Host "Using Unity method: $method"
# -----------------------------
# Run Unity build
# -----------------------------
Write-Host "===================================================================="
Write-Host "===================== Starting Unity Build ========================="
Write-Host "===================================================================="
# 1. Define arguments cleanly using an array
$logFile = "$PWD/unity_build.log"
$unityArgs = @(
"-batchmode",
"-nographics",
"-quit",
"-projectPath", "$PWD",
"-executeMethod", "$method",
"-logFile", "$PWD/unity_batch_build.log" # CRITICAL: Captures what goes wrong
"-logFile", "$logFile"
)
# Execute using the array
& $unityEditorPath @unityArgs
# 2. Start the Unity process in the background
$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
}
# -----------------------------
# Validate result
# -----------------------------
if ($exitCode -ne 0) {
throw "Unity build failed ($Target). Exit code: $exitCode"
# 4. Stream the log live into the TeamCity console
if (Test-Path $logFile) {
# Get-Content -Wait streams the file until the process kills it
$logJob = Start-Job -ScriptBlock { Get-Content $using:logFile -Wait }
# 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 "===================================="