简体   繁体   English

如何在 Azure DevOps 中使用 SharePointPnpPowerShellOnline PowerShell 模块?

[英]How to use SharePointPnpPowerShellOnline PowerShell module in Azure DevOps?

I am failing to use the SharePointPnpPowerShellOnline PS Module as part of my release pipeline.我没有将 SharePointPnpPowerShellOnline PS 模块用作发布管道的一部分。 We are using Azure DevOps with a hosted build agent on a Azure VM.我们将 Azure DevOps 与 Azure VM 上的托管构建代理结合使用。 I want to accomplish uploading build artifacts into Microsoft Teams/Sharepoint.我想完成将构建工件上传到 Microsoft Teams/Sharepoint。

  • I installed SharePointPnpPowerShellOnline on the server (under the account that the DevOps build agent operates with), yet the build agent fails to execute the script on the first line that uses said module (a call to Connect-PnPOnline -Url https://... -Credentials ... ).我在服务器上安装了 SharePointPnpPowerShellOnline(在 DevOps 构建代理使用的帐户下),但构建代理无法在使用所述模块的第一行执行脚本(调用Connect-PnPOnline -Url https://... -Credentials ... )。 Error message: "Connect-PnPOnline : The term 'Connect-PnPOnline' is not recognized as the name of a cmdlet, function, script file".错误消息:“Connect-PnPOnline:术语‘Connect-PnPOnline’未被识别为 cmdlet、函数、脚本文件的名称”。 So it behaves as if the module is not installed at all.所以它的行为就像根本没有安装模块一样。
  • yet when I log onto the server (with the correct account), the module is found and I can execute Connect-PnPOnline succesfully.但是当我登录到服务器(使用正确的帐户)时,找到了该模块并且我可以成功执行 Connect-PnPOnline。
  • the used Azure DevOps pipeline task is "PowerShell".使用的 Azure DevOps 管道任务是“PowerShell”。

Shouldn't the build agent be able to find the installed module, as I installed it for its user?构建代理是否应该能够找到已安装的模块,因为我为其用户安装了它?

Edit: I did some more "debugging", namely:编辑:我做了更多的“调试”,即:

  • logging the Username the script is running under by [Environment]::UserName, to make sure I installed the module for the right user.通过 [Environment]::UserName 记录运行脚本的用户名,以确保我为正确的用户安装了模块。 result: matches the expected user.结果:匹配预期用户。
  • Listing the installed modules by Get-InstalledModule in my script.在我的脚本中通过 Get-InstalledModule 列出已安装的模块。 Once it is executed in the Release pipeline by the agent it yields an empty list.一旦代理在发布管道中执行它,它就会产生一个空列表。 yet executing the same script on the VM (via RemoteDesktop) yields the installed modules但是在 VM 上执行相同的脚本(通过 RemoteDesktop)会产生已安装的模块

My guess is I'm doing a stupid beginner mistake because I haven't that much experience with PowerShell...我的猜测是我犯了一个愚蠢的初学者错误,因为我对 PowerShell 没有太多经验......

Answering my own question: In the end I just installed the Module again as part of the script by prepending the following two lines.回答我自己的问题:最后,我通过添加以下两行再次将模块安装为脚本的一部分。 Of course I'd be happy if somebody could explain why it didn't work the other way...当然,如果有人能解释为什么它不能以其他方式工作,我会很高兴......

Install-PackageProvider Nuget -ForceBootstrap -Force
Install-Module -Name SharePointPnPPowerShellOnline -Force -Verbose -Scope CurrentUser

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 Azure DevOps 存储库上使用 Powershell 模块 - Unable to use Powershell Module on Azure DevOps Repo Azure Devops - 如何使用 powershell 命令运行 SQL 脚本 - Azure Devops - How to use a powershell command to run SQL Scripts 如何在 Azure DevOps PowerShell 任务中使用预定义变量? - How to use predefined variables in Azure DevOps PowerShell Task? 在 Azure DevOps 管道中的 PowerShell 中使用参数 - Use parameter in PowerShell in Azure DevOps pipeline 如何针对 Azure DevOps 存储库中的特定分支使用 Azure Powershell Datafactory cmdlet? - How to use Azure Powershell Datafactory cmdlets against specific branches in Azure DevOps repositories? 如何在 Azure DevOps Azure Powershell 任务中启用 PowerShell 交互模式? - How to enable PowerShell Interactive mode in Azure DevOps Azure Powershell Task? 如何检测 Azure DevOps 代理上安装了哪个版本的 Az PowerShell 模块集合? - How to detect which version of the Az PowerShell module collection is installed on an Azure DevOps agent? 如何在 Powershell 中访问 Azure DevOps Stage name? - How to access Azure DevOps Stage name in Powershell? Azure DevOps PowerShell 任务无法加载“Az.CosmosDB”模块 - Azure DevOps PowerShell task fails to load 'Az.CosmosDB' module 在 azure-pipelines.yml powershell 脚本中使用 Azure Devops 变量 - Use Azure Devops variable in azure-pipelines.yml powershell script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM