使用 powershell 任务使用发布管道自动化 Azure 数据工厂触发器

Automate Azure Data Factory triggers using release pipeline by using powershell task

我是 DevOps 的新手,我正在尝试使用 powershell 在部署时更改 Azure 数据工厂触发器中的开始时间和结束时间属性。

我找到了这个 link 并尝试在 PowerShell 中进行操作。当我 运行 低于命令时出现以下错误。

PS C:\> Set-AzDataFactoryV2Trigger -ResourceGroupName "ADF" -DataFactoryName "WikiADF" -Name "ScheduledTrigger" -DefinitionFile ".\scheduledTrigger.json"

Set-AzureRmDataFactoryV2 : The term 'Set-AzureRmDataFactoryV2' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At line:1 char:16
+ $DataFactory = Set-AzureRmDataFactoryV2 -ResourceGroupName $ResGrp.Re ...
+                ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Set-AzureRmDataFactoryV2:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

我搜索了这个问题,发现这个问题是 Microsoft official github account

中的一个错误

如果有人能够解决这个问题或者已经解决了,请帮助我。

注意:Azure DataFactory Triggers 标签在 Whosebug 中不可用,所以我无法添加它。

非常同意尼克的意见:

Any time youe see The term 'xyz' is not recognized as the name of a cmdlet in powershell, it means you haven't installed the module.

其实你的issue中,也是这个原因导致的错误。我认为您应该没有为您的 Powershell 安装 Az 模块。

Az 模块是 Azure PowerShell cmdlet 的汇总模块。安装它可以下载所有可用的 Azure 资源管理器模块,包括您正在使用的 Set-AzDataFactoryV2Trigger,并使它们的 cmdlet 可供使用。

尝试使用此命令为您的 Powershell 安装 Az 模块:

Install-Module -Name Az -AllowClobber -Scope CurrentUser

由于默认情况下,PowerShell 库未配置为 PowerShellGet 的受信任存储库,您第一次使用 PSGallery 时会看到需要您的提示确保是否要从 PSGallery 获取 Az 模块。只需回答“是”或“是”即可。

然后,可以执行以下命令查看Az模块:

 Get-InstalledModule -Name Az

当您看到以下消息时,表示 Az 模块已存在于 Powershell 中:

现在,再试一次link,就成功了。

您似乎在发布管道中使用了 PowerShell 任务而不是 Azure PowerShell 任务 (https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-powershell?view=azure-devops)。

使用 Azure PowerShell 任务不会有任何问题。