powershell 脚本在 TeamCity 中的行为不同

powershell script behaves differently in TeamCity

简短摘要 - 尽管 Teamcity 代理已根据我的凭据设置为 运行,并且看起来它仍然像使用权限较低的帐户一样运行。

使用我的凭据将构建代理服务设置为 运行,我可以在服务小程序中看到它。

构建有一个简单的 powershell 脚本,它使用 IE COM 对象在 IE 中加载页面。

$IE=new-object -com internetexplorer.application 
$IE.visible=$true 
$IE.navigate2("https://myurl.com/location")

我还有一个单独的命令脚本,将网络驱动器映射到 webDAV 位置。

NET USE Y:  https://myurl.com/location

这两个 运行 从命令行都可以。

我已确认脚本正在我的帐户下执行 通过 运行宁

echo $([Environment]::UserName)

在 powershell 中并使用

whoami

驱动器映射脚本命令。

对于 powershell 我得到错误

new-object : Retrieving the COM class factory for component with CLSID 
{0002DF01-0000-0000-C000-000000000046} failed due to the following error:
 80080005 Server execution failed (Exception from HRESULT: 0x80080005
 (CO_E_SERVER_EXEC_FAILURE)).
 At line:1 char:5
 $IE=new-object -com internetexplorer.application
 CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
 FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

对于我得到的驱动器映射脚本

  "The system cannot find the drive specified."

请注意,我还尝试 运行 NET USE 作为脚本的一部分来查看映射了哪些驱动器,但它没有显示驱动器,即使我在 运行ning 之前手动映射了它脚本。

可能是我自己偶然发现了答案。

似乎 运行 作为一项 windows 服务对权限有影响。

https://confluence.jetbrains.com/display/TCD8/Known+Issues#KnownIssues-Windowsservicelimitations

解决方案是在服务控制台之外手动启动代理。