【发布时间】:2020-04-11 01:48:27
【问题描述】:
问题:尝试通过 powershell 创建 ADF 组件(例如 AzureSQLMITable 的数据集)时 ADF 出错
分析:
错误可在 BuildServer(通过 DevOps 运行)和本地通过 Windows PowerShell 重现。
使用相同的命令集在 Azure Cloudshell 和 Powershell 核心中无法重现错误
数据集的 ADF 错误:
无法加载资源#datasetname。请确保 JSON 中没有错误并且存在引用的资源。状态:UnknownError,可能的原因:命名的获取失败:dataset$#datasetname。未找到适配器。类型:数据集。
如果在 ADF 中手动粘贴文件(jsonfile),它会按预期工作而不会出错
预期的解决方案:如何使其与 WindowsPowershell 一起工作?
Json 文件:
{
"name": "#datasetname",
"properties": {
"linkedServiceName": {
"referenceName": "<connection name>",
"type": "LinkedServiceReference"
},
"annotations": [],
"type": "AzureSqlMITable",
"schema": [],
"typeProperties": {
"tableName": {
"value": "<StoredProcedure_Name_Name>",
"type": "Expression"
}
}
},
"type": "Microsoft.DataFactory/factories/datasets"
}
Powershell 命令:
Connect-AzureRmAccount
$BaseFolder=<FilePath>
$file = Get-ChildItem $BaseFolder -Recurse -Include *.json -Filter #somefilter -ErrorAction Stop
Set-AzureRmDataFactoryV2Dataset -DataFactoryName <datafactoryname> -Name ($file.BaseName) -ResourceGroupName <resourcegroupname> -DefinitionFile $file.FullName -Force -ErrorAction Stop
【问题讨论】:
-
Get-ChildItem返回(在您的情况下).json 文件的 array。更好地使用-Filter '*.json'并遍历结果 -
@Theo 好的。但这不是问题,问题是数据集没有正确创建
-
因为我猜
$file.BaseName也会产生一个数组而不是单个字符串 -
使用 Powershell 核心命令通过 Az 命令解决(通过 CICD 中的 Azure Powershell 任务而不是 Windows 的 Powershell 脚本)
-
@akshayslodha 恭喜您解决了问题。我帮你把它作为答案发布,你可以考虑接受(标记)它(单击答案旁边的复选标记将其从灰色切换为已填充。),这对其他社区成员可能会有所帮助。您也可以自己发布更多详细信息,我将删除答案。谢谢!
标签: azure powershell azure-sql-database azure-data-factory-2