问题描述
我有一个在交互模式下运行 Azure Devops 代理的 Windows 10 企业虚拟机。代理使用机器拥有的唯一用户运行,并且它是禁用 UAC 的管理员。但是,在执行需要提升命令提示符的任务时,如注册 dll,该命令会失败并显示以下错误消息:
##[error]Cmd.exe exited with code '5'.
当我尝试将文件复制到 Windows\SysWow64 时,就会出现此消息
##[error]Error: Failed cp: cp: copyFileSync: Could not write to dest file (code=EPERM):C:\windows\SysWow64\test.txt
Test method TestesRegressaoPGB.Autenticacao.AutenticarnopGBL02 threw exception:
System.AggregateException: One or more errors occurred. (The requested operation requires elevation.) ---> System.ComponentModel.Win32Exception: The requested operation requires elevation.
TestCleanup method TestesRegressaoPGB.Autenticacao.Cleanup threw exception. System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object..
如何在提升时运行所有命令?
解决方法
在 Azure DevOps 中,如果您想通过自托管代理访问 azure devops 管道中的本地文件,它会通过 service account
而不是 Personal account
访问文件。
解决方法
我们可以打开检查文件权限并配置服务帐户权限。服务帐户格式 User/Administrator/Administrators({Agent.ComputerName}\User/Administrator/Administrators)
此外,我们可以将代理服务帐户更改为您的所有者帐户。
操作步骤:在代理机器上打开服务,搜索代理服务账号,查看下图,把账号名和密码改成你自己的,就可以用这个账号进行操作了。
,我刚刚为管道代理需要打开的每个文件夹添加了权限。正如我对 Vito 所说的,代理没有使用服务帐户运行。