unity-azure-pipelines-tasks icon indicating copy to clipboard operation
unity-azure-pipelines-tasks copied to clipboard

Feature Request: Download Unity version if not installed/found

Open SimonDarksideJ opened this issue 3 years ago • 1 comments

Given the frequency of Unity builds appearing sometimes, it takes a lot of time to keep the build server up to date ahead of development.

It would be great to have an additional build task to automatically download and install the required Unity version as noted in the ProjectSettings.txt

SimonDarksideJ avatar May 17 '21 18:05 SimonDarksideJ

I know this is not directly what you ask for, but this is a way we use to automatically install Unity, as an Azure DevOps template. With good help from https://github.com/sttz/install-unity :

parameters:
- name: unityComponents
- name: unityProjectRoot
  default: './'

steps:
- task: DinomiteStudios.64e90d50-a9c0-11e8-a356-d3eab7857116.custom-unity-get-project-version-task.UnityGetProjectVersionTask@1
  displayName: 'Unity Get Project Version'
  name: UnityGetProjectVersionTask
  inputs:
    unityProjectPath: '${{parameters.unityProjectRoot}}'

- task: PowerShell@2
  displayName: 'Download and install unity'
  inputs:
    targetType: inline
    script: |
      $unityFolder = ""
      $unityPath = ""
      if ($IsMacOS) {
        $Uri = "https://github.com/sttz/install-unity/releases/download/2.3.0/install-unity-2.3.0.zip"
        $unityExecutable = "/Unity.app/Contents/MacOS/Unity"
        Invoke-WebRequest -Uri $Uri -OutFile "install-unity.zip"
        Expand-Archive "install-unity.zip" -DestinationPath .
        chmod +x install-unity
        sudo ./install-unity install $(UnityGetProjectVersionTask.projectVersion) --packages '${{parameters.unityComponents}}' --opt progressBar=false
        if ($LASTEXITCODE -ne 0) { throw "Could not install unity" }

        # We used a common approach to get Unity installed on Windows and MacOS, but something broke with time in DevOps PowerShell, so we need a workaround
        $unityPath = Get-ChildItem -Path "/Applications/" -Filter Unity* | Select -Expand FullName

        $unityFolder = "$unityPath/Unity.app"
      } else {
        $Uri = "https://github.com/minorai/install-unity/releases/download/2.7.2-win2/install-unity.zip"
        $unityExecutable = "\Editor\Unity.exe"
        Invoke-WebRequest -Uri $Uri -OutFile "install-unity.zip"
        Expand-Archive "install-unity.zip" -DestinationPath .
        ./install-unity install $(UnityGetProjectVersionTask.projectVersion) --packages '${{parameters.unityComponents}}' --opt progressBar=false
        if ($LASTEXITCODE -ne 0) { throw "Could not install unity" }

        # install-unity list -i - returns installed Unities in the following format:
        # Unity version <---TAB---> Unity path
        $unityInstall = & .\install-unity list -i | Out-String
        $unityPath = $unityInstall.SubString($unityInstall.IndexOf("`t")).Trim()

        $unityFolder = "$unityPath"
      }
      $unityPath += $unityExecutable
      echo "Unity installation folder: $unityFolder"
      echo "Unity executable: $unityPath"
      echo "##vso[task.setvariable variable=UnityFolder]$unityFolder"
      echo "##vso[task.setvariable variable=UnityPath]$unityPath"
    errorActionPreference: stop

eirikwah avatar Nov 26 '21 09:11 eirikwah