【问题标题】:Problem loading Az.Kusto 2.0.0 PowerShell Module from Azure DevOps Pipeline从 Azure DevOps Pipeline 加载 Az.Kusto 2.0.0 PowerShell 模块时出现问题
【发布时间】:2023-03-28 16:51:01
【问题描述】:

要从我们的 Azure DevOps 管道自动配置 Azure 数据资源管理器数据库,我们使用 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) 我得到同样的错误。

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

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

【问题讨论】:

  • 确保在安装后手动导入:Import-Module Az.Kusto -RequiredVersion 2.0.0 -Force
  • 我们这样做了,但不幸的是错误保持不变。

标签: azure powershell azure-data-explorer kql


【解决方案1】:

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

# 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

【讨论】:

  • 感谢您的提示!我在原始帖子中记录了结果和其他信息。
【解决方案2】:

在一个新的空 DevOps 管道中隔离情况后,我找到了邪恶的根源。

在安装和导入 Az.Kusto 之前,这个导致所有麻烦的调用在哪里:

Import-Module Az

删除后,调用成功

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

从而提供对 New-AzKustoScript Cmdlet 的访问。

【讨论】:

    猜你喜欢
    • 2021-01-10
    • 1970-01-01
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多