gpt4 book ai didi

azure - 从 Azure DevOps Pipeline 加载 Az.Kusto 2.0.0 PowerShell 模块时出现问题

转载 作者:行者123 更新时间:2023-12-03 01:23:38 28 4
gpt4 key购买 nike

为了从 Azure DevOps Pipeline 自动配置 Azure Data Explorer 数据库,我们使用 PowerShell 模块 Az.Kusto。我们用来执行 KQL 脚本的函数是 New-AzKustoScript仅在最新版本的 Az.Kusto 中可用,因此我们运行以下指令作为 PowerShell 脚本的一部分,该脚本稍后调用 New-AzKustoScript:

Install-Module -Name Az.Kusto -RequiredVersion "2.0.0" -Force -Scope CurrentUser -AllowClobber

在我的本地开发计算机上,这是可行的,但是当我们作为 Azure DevOps Pipeline 的一部分运行此脚本时,我们会收到以下异常

2021-06-08T09:15:42.1278098Z $RuntimeException/   at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName, IScriptExtent errorPos)
2021-06-08T09:15:42.1413212Z at System.Management.Automation.Language.Compiler.NewOutputTypeAttribute(AttributeAst ast)
2021-06-08T09:15:42.1462865Z at System.Management.Automation.Language.Compiler.GetAttribute(AttributeAst attributeAst)
2021-06-08T09:15:42.1465059Z at System.Management.Automation.Language.ScriptBlockAst.<System-Management-Automation-Language-IParameterMetadataProvider-GetScriptBlockAttributes>d__68.MoveNext()
2021-06-08T09:15:42.1466223Z at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
2021-06-08T09:15:42.1485936Z at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
2021-06-08T09:15:42.1503023Z at System.Management.Automation.CompiledScriptBlockData.InitializeMetadata()
2021-06-08T09:15:42.1633625Z at Microsoft.Azure.PowerShell.Cmdlets.Kusto.Runtime.PowerShell.GetScriptCmdlet.<ProcessRecord>b__16_0(FunctionInfo fi)
2021-06-08T09:15:42.1635647Z at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
2021-06-08T09:15:42.1637257Z at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
2021-06-08T09:15:42.1693162Z at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
2021-06-08T09:15:42.1719336Z at Microsoft.Azure.PowerShell.Cmdlets.Kusto.Runtime.PowerShell.GetScriptCmdlet.ProcessRecord()
2021-06-08T09:15:43.3829832Z ##[error]Unable to find type [Microsoft.Azure.PowerShell.Cmdlets.Kusto.Models.Api202101.IOperation].
2021-06-08T09:15:43.5666125Z ##[error]PowerShell exited with code '1'.

任何帮助或提示将不胜感激。

更新:

  • 安装前卸载 Az.Kusto 失败并显示错误消息“没有删除任何模块。验证要删除的模块的规范是否正确以及这些模块是否存在于运行空间中。”

  • 我看到目录 C:\Modules\az_5.7.0 中安装了 Az.Kusto 版本 1.0.1。

  • 此外,当我在版本 2.0.0 中安装 Az.Kusto 时,此版本会安装在 C:\Users\VssAdministrator\Documents\WindowsPowerShell\Modules 中

  • 当我使用 Scope AllUsers 安装 Az.Kusto 时,模块显示在 C:\Program Files\WindowsPowerShell\Modules 下

  • 当我导入模块时,通过指定所需版本或传递 -Name 和路径 (Import-Module -Name "C:\Program Files\WindowsPowerShell\Modules\Az.Kusto\2.0.0\Az.Kusto.psm1"-Force -Global) 我得到同样的错误。

  • 2.3.0 版本中模块 Az.Accounts 安装在目录 C:\Modules\az_5.7.0 中

  • 我们在与 Install-Module 和 Import-Module 调用不同的 PowerShell 脚本中调用 New-AzKustoScript。这可能是一个问题吗?

最佳答案

在评论中添加另一个步骤,尝试一下:

# Unload existing version and reinstall without clobber - removing the module should remove overlaps
Remove-Module Az.Kusto
Install-Module -Name Az.Kusto -RequiredVersion "2.0.0" -Force -Scope CurrentUser
Import-Module Az.Kusto

版本 2.0.0 中的更新之一是需要稍微不同的 Az.Accounts 版本,因此也请检查一下:

RequiredModules = @(@{ModuleName = 'Az.Accounts'; ModuleVersion = '2.2.8'; }) 

以下是针对笨拙的 powershell 模块的一些故障排除步骤。导入模块后,将 Azure 上获得的输出与开发计算机上的输出进行比较:

# Check the loaded module:
Get-Module Az.Kusto | FL Name,Version,Path,

# On your local, try finding the missing type and the dll loading it:
[Microsoft.Azure.PowerShell.Cmdlets.Kusto.Models.Api202101.IOperation]|fl Name,Module

您可以通过Import-Module/azure/module/path/to.dll手动导入任何丢失的dll。或者,您可能会发现由于整个 az.Kusto 模块抑制的某些错误而无法导入该 dll。

无论哪种方式,您可能需要尝试联系模块创建者 - 版本 2.0.0 还不到 3 周,并且存在一些其他已知问题:https://github.com/Azure/azure-powershell/issues?q=is%3Aissue+is%3Aopen+kusto

关于azure - 从 Azure DevOps Pipeline 加载 Az.Kusto 2.0.0 PowerShell 模块时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67887159/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com