Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Bug Hub CLI sometimes lists installed Unity versions and sometimes doesn't

Discussion in 'Unity Hub' started by Andrew-Silverblade, Jul 3, 2020.

  1. Andrew-Silverblade

    Andrew-Silverblade

    Joined:
    Mar 14, 2015
    Posts:
    2
    Hi there,

    I'm in the process of setting up Continuous Integration using Gitlab. It seems like the official way to finding installed Editors is using the Unity Hub to enumerate them, so I am using

    Code (csharp):
    1. "C:\Program Files\Unity Hub\Unity Hub.exe" -- --headless editors
    The following is my .gitlab-ci.yml file:
    Code (csharp):
    1. stages:
    2.     - test-editor
    3.  
    4. before_script:
    5.     - |
    6.         $projectVersion = (Select-String -Pattern "^m_EditorVersion: (.*)$" -Path ".\ProjectSettings\ProjectVersion.txt").Matches[0].Groups[1].Value
    7.  
    8.         Write-Output ([string]::Format("Project Version: {0}", $projectVersion))
    9.                
    10.         # Get Installed Editor Versions
    11.         [Diagnostics.ProcessStartInfo]$pInfo = [Diagnostics.ProcessStartInfo]::new()
    12.         $pInfo.FileName = "C:\Program Files\Unity Hub\Unity Hub.exe"
    13.         $pInfo.RedirectStandardOutput = $true
    14.         $pInfo.RedirectStandardError = $true
    15.         $pInfo.useShellExecute = $false
    16.         $pInfo.Arguments = "-- --headless editors"
    17.         [Diagnostics.Process]$process = [Diagnostics.Process]::new()
    18.         $process.StartInfo = $pInfo
    19.         $started = $process.Start()
    20.         if ($started -eq $false)
    21.         {
    22.             Write-Error "Failed to start Unity Hub"
    23.             exit -1
    24.         }
    25.        
    26.         # Give the Unity Hub some time to find local installations.
    27.         Start-Sleep -s 5
    28.        
    29.         $unityHubOutput = $process.StandardOutput.ReadToEnd();
    30.         $unityHubError = $process.StandardError.ReadToEnd();
    31.        
    32.        
    33.        
    34.         $exited = $process.WaitForExit(20000)
    35.         if ($exited -eq $false)
    36.         {
    37.             $process.Kill()
    38.             Write-Error "Unity Hub did not print installed versions after 20s. Killed it."
    39.             exit -1
    40.         }
    41.        
    42.         echo "===== Hub Output ====="
    43.         echo $unityHubOutput
    44.         echo "======================"
    45.        
    46.         if ($unityHubError -ne "")
    47.         {
    48.             Write-Error $unityHubError
    49.         }
    50.                
    51.         # Find required editor version
    52.         $versionSearchPattern = [string]::Format("{0}[ \t], installed at (.*)", $projectVersion)
    53.         $editorMatch = Select-String -Pattern $versionSearchPattern -InputObject $unityHubOutput
    54.                
    55.         if (!$editorMatch) {
    56.             Write-Error "Failed to find a Unity Editor matching the project version. Is it installed on this runner?"
    57.             exit -1
    58.         } else {
    59.             echo "Found Unity"
    60.             echo $editorMatch.Matches[0].Groups[1]
    61.         }
    62.        
    63.  
    64. editor-tests:
    65.     stage: test-editor
    66.     tags:
    67.         - unity
    68.     script:
    69.         - |
    70.             echo "Not doing anything yet."
    The weird thing that's happening now is that sometimes, I get as output:

    Code (csharp):
    1. 2018.4.24f1
    2. 2019.3.15f1
    3. 2019.4.2f1
    4. 2020.1.0b14
    5. 2020.2.0a16
    And at other times:

    Code (csharp):
    1. 2018.4.24f1
    2. 2019.3.15f1
    3. 2019.4.2f1
    4. 2020.1.0b14
    5. 2020.2.0a16
    6. 2019.4.1f1 , installed at C:\Program Files\Unity\2019.4.1f1\Editor\Unity.exe
    7. 2019.2.6f1 , installed at C:\Program Files\Unity\2019.2.6f1\Editor\Unity.exe
    It might be because of the weird way the Unity Hub seems to print to terminals, because the prompt is returned before the version information is written.

    I've been trying to get this to work reliably for hours now but it just does not want to work. Is this a problem on my side or yours?
     
unityunity