通过 Jenkins 通过 Powershell 插件安装 appx

Install appx through Powershell Plugin via Jenkins

我在尝试使用 Jenkins 中的 Powershell 插件 Powershell -ExecutionPolicy Unrestricted add-appxpackage <path to appx> 安装 appx 时遇到问题,并记录了以下错误:

add-appxpackage : Deployment failed with HRESULT: 0x80073CF9, Install failed. Please contact your software vendor. (Exception from HRESULT: 0x80073CF9) Deployment Add operation rejected on package <path to appx> install request because the Local System account is not allowed to perform this operation. NOTE: For additional information, look for [ActivityId].

据我了解,这个问题主要是因为 Windows 上的 Jenkins 服务被安装为 NT Authority\System。 (如果我使用 psexec.exe 打开 运行 作为 Authority\System 的命令提示符,我 运行 会遇到同样的问题。)然后我尝试添加 net localgroup "Administrators" NT Authority\System /add 希望该组可能会被添加为管理员,并让我安装 appx,因此我可以 运行 进行测试,但没有成功。现在我被卡住了,我不确定是否真的有办法通过 Jenkins 安装 appx,或者是否有办法通过 Jenkins 以管理员身份调用 Powershell 脚本。我已经浏览过几个 SO 链接,但其中 none 似乎解决了我面临的问题。任何指针将不胜感激。

不要 尝试将系统添加到管理员组,这是一个受限帐户,不需要管理权限。

而是将 Jenkins 服务更改为 运行 作为对您尝试执行的操作具有正确权限的用户。这可能意味着您需要专门为 Jenkins 服务创建一个帐户。

有几种更改服务帐户的方法,this answer 提供以下解决方案:

sc.exe config "Service Name" obj= "DOMAIN\User" password= "password"