-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild-windows-powershell.ps1
67 lines (51 loc) · 2.77 KB
/
build-windows-powershell.ps1
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Stop PowerShell on first error
$ErrorActionPreference = "Stop"
Write-Host "$(date) Starting build script"-ForegroundColor green
Write-Host "Running as '$env:UserName' on domain '$env:UserDomain' on system '$env:ComputerName'"
Set-ExecutionPolicy Bypass -Scope Process -Force
Write-Host "$(date) Getting unity instance"-ForegroundColor green
$username = $env:UNITY_USERNAME
$password = $env:UNITY_PASSWORD
Write-Host "$(date) Creating non-interactive credential object for password"-ForegroundColor green
$secure_password = ConvertTo-SecureString $password -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential ($username, $secure_password)
$build_target = $env:BUILD_TARGET
$serial_env_key = $build_target.ToUpper() + "_UNITY_SERIAL"
$serial = (get-item env:$serial_env_key).Value
$secure_serial = ConvertTo-SecureString $serial -AsPlainText -Force
$build_name = $env:BUILD_NAME
$build_path = "./Builds/$build_target/"
$build_log = ".\build.log"
# Don't mind errors here
# You will see the following error in the logs but it's safe and build continues, it's just annoying:
# Get-YamlDocuments : Exception calling "Load" with "1" argument(s): "(Line: 1, Col: 1, Idx: 0) - (Line: 1, Col: 2, Idx:
$ErrorActionPreference = "Continue"
New-Item -Path $build_path -ItemType "directory"
Write-Host "$(date) Starting unity editor with method execution"-ForegroundColor green
$editor = $UNITY_EXECUTABLE
$process = New-Object System.Diagnostics.Process
$process.StartInfo.Filename = $editor
$process.StartInfo.Arguments = $unityArgs
$process.StartInfo.RedirectStandardOutput = $true
$process.StartInfo.RedirectStandardError = $true
$process.StartInfo.UseShellExecute = $false
$process.StartInfo.CreateNoWindow = $true
$process.StartInfo.WorkingDirectory = $PWD
$process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
$process.Start() | Out-Null
## This uses https://github.com/Microsoft/unitysetup.powershell it worked out of gitlab-ci, but I was not able to get it to work when running from gitlab-runner
# Start-UnityEditor `
# -Credential $credentials `
# -Serial $secure_serial `
# -BatchMode `
# -Quit `
# -LogFile $build_log `
# -ExecuteMethod BuildCommand.PerformBuild `
# -buildTarget $build_target `
# -Wait `
# -AdditionalArguments "-customBuildTarget $build_target -customBuildName $build_name -customBuildPath $build_path -customBuildOptions AcceptExternalModificationsToPlayer"
# Stop PowerShell on first error
$ErrorActionPreference = "Stop"
Write-Host "$(date) Reading build logs"-ForegroundColor green
Get-Content -Path $build_log
Write-Host "$(date) Done with unity build. Output log saved to $build_log"-ForegroundColor green