more
This commit is contained in:
Vendored
+58
@@ -8,12 +8,70 @@ project {
|
|||||||
|
|
||||||
description = "Unity CI - isolated platform builds"
|
description = "Unity CI - isolated platform builds"
|
||||||
|
|
||||||
|
buildType(UnityLicenseActivation)
|
||||||
buildType(WindowsBuild)
|
buildType(WindowsBuild)
|
||||||
buildType(AndroidBuild)
|
buildType(AndroidBuild)
|
||||||
buildType(MacBuild)
|
buildType(MacBuild)
|
||||||
buildType(IOSBuild)
|
buildType(IOSBuild)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UNITY LICENSE ACTIVATION
|
||||||
|
* Run once per agent/machine or when licenses expire
|
||||||
|
*/
|
||||||
|
object UnityLicenseActivation : BuildType({
|
||||||
|
|
||||||
|
name = "Unity - License Activation"
|
||||||
|
|
||||||
|
vcs {
|
||||||
|
root(DslContext.settingsRoot)
|
||||||
|
}
|
||||||
|
|
||||||
|
params {
|
||||||
|
param("unity.executable", "C:/Program Files/Unity/Hub/Editor/2022.3.XXf1/Editor/Unity.exe")
|
||||||
|
|
||||||
|
// Store these as secure parameters in TeamCity (DO NOT hardcode)
|
||||||
|
password("unity.email", "credentialsJSON:REPLACE_ME")
|
||||||
|
password("unity.password", "credentialsJSON:REPLACE_ME")
|
||||||
|
password("unity.serial", "credentialsJSON:REPLACE_ME")
|
||||||
|
}
|
||||||
|
|
||||||
|
steps {
|
||||||
|
|
||||||
|
powerShell {
|
||||||
|
name = "Activate Unity License"
|
||||||
|
|
||||||
|
scriptContent = """
|
||||||
|
Write-Host "Checking Unity license activation..."
|
||||||
|
|
||||||
|
$unity = "%unity.executable%"
|
||||||
|
|
||||||
|
if (!(Test-Path $unity)) {
|
||||||
|
throw "Unity executable not found at: $unity"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Running Unity license activation..."
|
||||||
|
|
||||||
|
& $unity -quit -batchmode -nographics `
|
||||||
|
-serial "%unity.serial%" `
|
||||||
|
-username "%unity.email%" `
|
||||||
|
-password "%unity.password%" `
|
||||||
|
-logFile -
|
||||||
|
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
throw "Unity license activation failed (exit code: $LASTEXITCODE)"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Unity license activated successfully"
|
||||||
|
""".trimIndent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
requirements {
|
||||||
|
equals("teamcity.agent.os", "Windows")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WINDOWS (also builds Android on Windows agent)
|
* WINDOWS (also builds Android on Windows agent)
|
||||||
*/
|
*/
|
||||||
|
|||||||
+29
-19
@@ -99,8 +99,15 @@ try {
|
|||||||
Write-Host "===================== Starting Unity Build ========================="
|
Write-Host "===================== Starting Unity Build ========================="
|
||||||
Write-Host "===================================================================="
|
Write-Host "===================================================================="
|
||||||
|
|
||||||
# 1. Define arguments cleanly using an array
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
||||||
|
# 1. Define paths
|
||||||
$logFile = "$PWD/unity_build.log"
|
$logFile = "$PWD/unity_build.log"
|
||||||
|
$artifactLog = "$PWD/BuildLog/unity_build.log"
|
||||||
|
|
||||||
|
New-Item -ItemType Directory -Force -Path "$PWD/BuildLog" | Out-Null
|
||||||
|
|
||||||
|
# 2. Build arguments
|
||||||
$unityArgs = @(
|
$unityArgs = @(
|
||||||
"-batchmode",
|
"-batchmode",
|
||||||
"-nographics",
|
"-nographics",
|
||||||
@@ -110,30 +117,33 @@ try {
|
|||||||
"-logFile", "$logFile"
|
"-logFile", "$logFile"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 2. Start the Unity process in the background
|
Write-Host "Starting Unity..."
|
||||||
$process = Start-Process -FilePath $unityEditorPath -ArgumentList $unityArgs -PassThru -NoNewWindow
|
Write-Host "Log: $logFile"
|
||||||
|
|
||||||
# 3. Wait for the log file to be created by Unity
|
# 3. Start Unity
|
||||||
while (!(Test-Path $logFile) -and !$process.HasExited) {
|
$process = Start-Process `
|
||||||
Start-Sleep -Milliseconds 100
|
-FilePath $unityEditorPath `
|
||||||
|
-ArgumentList $unityArgs `
|
||||||
|
-NoNewWindow `
|
||||||
|
-PassThru
|
||||||
|
|
||||||
|
# 4. Stream log live (simple + reliable)
|
||||||
|
while (-not $process.HasExited) {
|
||||||
|
if (Test-Path $logFile) {
|
||||||
|
Get-Content $logFile -Tail 20 -ErrorAction SilentlyContinue | ForEach-Object {
|
||||||
|
Write-Host $_
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Start-Sleep -Milliseconds 500
|
||||||
}
|
}
|
||||||
|
|
||||||
# 4. Stream the log live into the TeamCity console
|
$process.WaitForExit()
|
||||||
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
|
# 5. Copy Log to Builds Folder
|
||||||
$process.WaitForExit()
|
Copy-Item $logFile $artifactLog -Force
|
||||||
|
|
||||||
# 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
|
# 6. Exit handling
|
||||||
if ($process.ExitCode -ne 0) {
|
if ($process.ExitCode -ne 0) {
|
||||||
Write-Error "Unity build failed with exit code $($process.ExitCode)"
|
Write-Error "Unity build failed with exit code $($process.ExitCode)"
|
||||||
exit $process.ExitCode
|
exit $process.ExitCode
|
||||||
|
|||||||
Reference in New Issue
Block a user