more
This commit is contained in:
Vendored
+58
@@ -8,12 +8,70 @@ project {
|
||||
|
||||
description = "Unity CI - isolated platform builds"
|
||||
|
||||
buildType(UnityLicenseActivation)
|
||||
buildType(WindowsBuild)
|
||||
buildType(AndroidBuild)
|
||||
buildType(MacBuild)
|
||||
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)
|
||||
*/
|
||||
|
||||
+31
-21
@@ -99,8 +99,15 @@ try {
|
||||
Write-Host "===================== Starting Unity Build ========================="
|
||||
Write-Host "===================================================================="
|
||||
|
||||
# 1. Define arguments cleanly using an array
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# 1. Define paths
|
||||
$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 = @(
|
||||
"-batchmode",
|
||||
"-nographics",
|
||||
@@ -110,30 +117,33 @@ try {
|
||||
"-logFile", "$logFile"
|
||||
)
|
||||
|
||||
# 2. Start the Unity process in the background
|
||||
$process = Start-Process -FilePath $unityEditorPath -ArgumentList $unityArgs -PassThru -NoNewWindow
|
||||
Write-Host "Starting Unity..."
|
||||
Write-Host "Log: $logFile"
|
||||
|
||||
# 3. Wait for the log file to be created by Unity
|
||||
while (!(Test-Path $logFile) -and !$process.HasExited) {
|
||||
Start-Sleep -Milliseconds 100
|
||||
# 3. Start Unity
|
||||
$process = Start-Process `
|
||||
-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
|
||||
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
|
||||
}
|
||||
$process.WaitForExit()
|
||||
|
||||
# 5. Bubble up the exit code so TeamCity catches errors
|
||||
# 5. Copy Log to Builds Folder
|
||||
Copy-Item $logFile $artifactLog -Force
|
||||
|
||||
|
||||
# 6. Exit handling
|
||||
if ($process.ExitCode -ne 0) {
|
||||
Write-Error "Unity build failed with exit code $($process.ExitCode)"
|
||||
exit $process.ExitCode
|
||||
|
||||
Reference in New Issue
Block a user