如何在Azure DevOps中设置构建统一项目的管道

问题描述

我是创建管道的新手,我需要创建一个管道来构建我的统一项目和C#脚本。我尝试这个:

https://dinomite-studios.github.io/unity-azure-pipelines-tasks/hosted-agent.html(在此尝试中,我没有Unity Active License序列号,因此我删除了此任务,但第二个PowerShell脚本未通过),我得到此错误

Starting: PowerShell Script
==============================================================================
Task         : PowerShell
Description  : Run a PowerShell script on Linux,macOS,or Windows
Version      : 2.170.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
==============================================================================
Generating script.
========================== Starting Command Output ===========================
"C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Nologo -noprofile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\2178f08e-dbac-43f8-a053-1a2420d6c47c.ps1'"
Find-UnitySetupInstaller : The term 'Find-UnitySetupInstaller' is not recognized as the name of a cmdlet,function,script file,or operable program. Check the spelling of the name,or if a path was included,verify that the path is 
correct and try again.
At D:\a\_temp\2178f08e-dbac-43f8-a053-1a2420d6c47c.ps1:3 char:41
+ ... tall-UnitySetupInstance -Installers (Find-UnitySetupInstaller -Versio ...
+                                          ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Find-UnitySetupInstaller:String) [],ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException
 
##[error]PowerShell exited with code '1'.
Finishing: PowerShell Script

这:

https://medium.com/medialesson/continuous-integration-for-unity-3d-projects-using-azure-pipelines-e61ddf64ad79为此,我收到此错误

Starting: Unity Build Android
==============================================================================
Task         : Unity Build
Description  : Build a Unity project and get the exported output files.
Version      : 3.1.1
Author       : Dinomite Studios
Help         : Builds a Unity project to supported build target platforms. [More @R_816_4045@ion](https://github.com/Dinomite-Studios/unity-azure-pipelines-tasks)
==============================================================================
Determining Unity editor version for project at D:\a\1\s\virtualterminal-realwear\VirtualTerminal
Success,Unity editor version found 2019.3.9f1,alpha=false,beta=false
Unable to locate executable file: 'C:\Program Files\Unity\Hub\Editor\2019.3.9f1\Editor\Unity.exe'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.
##[error]Unable to locate executable file: 'C:\Program Files\Unity\Hub\Editor\2019.3.9f1\Editor\Unity.exe'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.
Finishing: Unity Build Android

我只尝试执行“ VisualStudioBuild”任务,但没有任何效果

有人可以告诉我该怎么做吗?

解决方法

Find-UnitySetupInstaller:术语“ Find-UnitySetupInstaller”不是 识别为cmdlet,函数,脚本文件或可操作文件的名称 程序。

对于遇到的第一个错误,如果查看第一个Powershell任务的日志,则会发现一条警告消息:WARNING: User declined to install module (UnitySetup)。换句话说,即使任务以绿色通过,模块UnitySetup也未成功安装。我们的Azure devops系统拒绝安装此模块。

这就是为什么您遇到the cmdlet xxx is not recognized错误的原因。这是因为父模块UnitySetup尚未成功安装。

要解决此问题,在第一个Powershell任务的-Force命令之后需要附加Install-module parameter

Install-Module UnitySetup -AllowPrerelease -Scope CurrentUser -Force 

## [错误]无法找到可执行文件:'C:\ Program Files \ Unity \ Hub \ Editor \ 2019.3.9f1 \ Editor \ Unity.exe'。

根据您共享的第二个日志,您正在使用托管代理,对吗?而且似乎您也没有添加Unity Get Project Version taskPowershell tasks来将 Unity 工具安装到环境中,因为您正在遵循此blog的管道定义示例。>

如果仔细查看该博客,您会发现该博客作者已在本地计算机上预安装了自己的自助代理,然后再在Azure devops中配置管道以及在其上安装的Unity Hub代理商。

enter image description here

简而言之,Unity.exe已存在于作者的构建环境中,因此此处省略了使用Powershell脚本安装Unity的步骤。但是我们的Hosted Agent尚未在我们的计算机中安装此可执行文件,这意味着您在使用Hosted Agent时必须自己安装它。


我认为,我强烈建议您关注您提到的第二个博客来配置管道,以节省构建执行时间:

1)。首先安装自我代理。

2)安装Unity.exe和所需的统一版本。

3)配置管道。