|
| 1 | +--- |
| 2 | +id: unity-setup-task |
| 3 | +title: Unity Setup |
| 4 | +--- |
| 5 | + |
| 6 | +## About |
| 7 | + |
| 8 | +Use the Unity Setup task to install a Unity editor version on the build agent. This is especially useful when working with hosted agents, |
| 9 | +where you do not know whether the Unity version your project needs to build is installed on the agent. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Inputs |
| 14 | + |
| 15 | +This task supports input variables for configuration. |
| 16 | + |
| 17 | +### unityEditorsPathMode |
| 18 | + |
| 19 | +For the task to run successfully it needs to know where Unity installations are located at on the agent. This input lets you configure, |
| 20 | +where the task should look for installations. |
| 21 | + |
| 22 | +**Required**: Yes |
| 23 | + |
| 24 | +**Default Value**: unityHub |
| 25 | + |
| 26 | +#### Options: |
| 27 | + |
| 28 | +| Value | Description | |
| 29 | +| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | |
| 30 | +| unityHub | Uses the Unity Hub default installation path. | |
| 31 | +| environmentVariable | Expects an environment variable `UNITYHUB_EDITORS_FOLDER_LOCATION` to exist on the agent and specifying where to find editor installations. | |
| 32 | +| specify | Let's you specify a custom path where to lookup editor installations using the input `customUnityEditorsPath`. | |
| 33 | + |
| 34 | +### customUnityEditorsPath |
| 35 | + |
| 36 | +If you are using a custom buld agent you may want to specify a custom path to specify where to look for Unity installations. This input lets you do that. |
| 37 | +Make sure to set `unityEditorsPathMode` to `specify` for this input to take effect. |
| 38 | + |
| 39 | +**Required**: Yes, if `unityEditorsPathMode` set to `specify` |
| 40 | + |
| 41 | +**Default Value**: - |
| 42 | + |
| 43 | +### unityProjectPath |
| 44 | + |
| 45 | +Enter the directory path to the Unity project. If no value is entered, the project is assumed to be in the repository root. |
| 46 | + |
| 47 | +**Required**: No |
| 48 | + |
| 49 | +**Default Value**: - |
| 50 | + |
| 51 | +### cmdArgs |
| 52 | + |
| 53 | +Specify command line arguments to pass to the Unity process when running the task. |
| 54 | + |
| 55 | +:::warning |
| 56 | + |
| 57 | +The task will set `-batchmode`, `-projectPath` and `-logfile` for you and you shouldn't specify them in your custom command line arguments. These three arguments are currently required to be always set for the task to work as designed. |
| 58 | + |
| 59 | +::: |
| 60 | + |
| 61 | +**Required**: Yes |
| 62 | + |
| 63 | +**Default Value**: - |
| 64 | + |
| 65 | +#### Options: |
| 66 | + |
| 67 | +Check the official [Unity command line documentation](https://docs.unity3d.com/Manual/CommandLineArguments.html) for options. |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## Outputs |
| 72 | + |
| 73 | +This task provides output variables. |
| 74 | + |
| 75 | +### logsOutputPath |
| 76 | + |
| 77 | +Path to the Unity editor log files generated while executing the task. Use this e.g. to upload logs in case of a failure. |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## How to use |
| 82 | + |
| 83 | +Here's a simple example of how to use and define the task in your pipeline. For more examples, check the [Examples Collection](./examples.md). |
| 84 | + |
| 85 | +### YAML |
| 86 | + |
| 87 | +In the simple YAML example below we are definiing the task a step in the pipeilne using `- task: UnityCMDTask@1`. We are also giving the task a reference name using `name: unitycmd`, so we can use it to refernce the output variables of the task in other tasks of the pipeline. E.g. we can output the value of the `logsOutputPath` output variable to the console using `echo $(unitycmd.logsOutputPath)`. For `cmdArgs` we specify that Unity should target the `standalone` platform and execute our custom build script `MyBuildTools.BuildProject` to perform the build. |
| 88 | + |
| 89 | +```yaml |
| 90 | +trigger: |
| 91 | +- main |
| 92 | + |
| 93 | +pool: |
| 94 | + name: Unity Windows |
| 95 | + |
| 96 | +steps: |
| 97 | +- task: UnityCMDTask@1 |
| 98 | + name: unitycmd |
| 99 | + inputs: |
| 100 | + unityEditorsPathMode: unityHub |
| 101 | + cmdArgs: -buildTarget standalone -executeMethod MyBuildTools.BuildProject |
| 102 | + |
| 103 | +- script: | |
| 104 | + echo $(unitycmd.logsOutputPath) |
| 105 | +``` |
| 106 | +
|
| 107 | +### Classic Pipeline Editor |
| 108 | +
|
| 109 | +The classic (visual) editor for Azure Pipelines provides input fields for configuring the task. In the simple example below, we set `Unity editors location` to use the default Unity Hub installation path to lookup installed Unity editor versions on the agent running our pipeline. We are also leaving the `Unity project path` field empty, since we know our Unity project is in the repository root. For `Command line arguments` we specify that Unity should target the `standalone` platform and execute our custom build script `MyBuildTools.BuildProject` to perform the build. We are also assigning a `Reference name` to the task, so we can use it to refernce the output variables in the variables list in other tasks of the pipeline. E.g. to get the value of the `logsOutputPath` output variable and insert it into any other input field of a task we can then use `$(unitycmd.logsOutputPath)`. |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## Log |
| 116 | + |
| 117 | +When run and successful the task will provide log output similar to this: |
| 118 | + |
| 119 | + |
0 commit comments