如何将保存在 azure devops git 存储库中的 JSON 文件的文件路径提供给 PowerShell script.Getting 文件未找到异常

How to provide file path of JSON file kept in azure devops git repository to PowerShell script.Getting file not found exception

enter image description here我正在尝试通过 Azure 发布管道 运行 此 PowerShell 脚本。 Azure 提供 json 文件和 PowerShell 脚本来部署数据工厂的链接服务或数据集。但是假定 json 文件的路径是本地计算机的路径。但是在通过 azure Devops 发布管道执行相同操作时,如何在 PowerShell 脚本中提供 json 文件路径并执行 Devops 发布管道。

Powershell 脚本 -

Set-AzDataFactoryV2LinkedService -DataFactoryName“DemoADF”-ResourceGroupName "DemoRG" -Name "AzureStorageLinkedService" -定义文件“./LinkedService.json”

LinkedService.json 文件 -

{ “名称”:“AzureStorageLinkedService”, “特性”: { “类型”:“AzureStorage”, “类型属性”:{ “connectionString”:“ConnectionStringDetails” }, “连接通过”:{ "referenceName": "AutoResolveIntegrationRuntime", “类型”:“集成运行时参考” } } }

尝试使用 - $env:(System.DefaultWorkingDirectory)/LinkedService.json 但不工作

Azure DevOps 发布管道错误 -

2020-07-28T04:23:31.1358415Z ##[debug]Error record:
2020-07-28T04:23:31.2243264Z ##[debug]Set-AzDataFactoryV2LinkedService : ./LinkedService.json
2020-07-28T04:23:31.2263866Z ##[debug]At D:\a\r1\a\LS_adf\ykfactory\AllADFDeploymentTasks\LinkedService.ps1:1 char:1
2020-07-28T04:23:31.2280510Z ##[debug]+ Set-AzDataFactoryV2LinkedService -DataFactoryName "DataFlowADFVNet" `
2020-07-28T04:23:31.2312596Z ##[debug]+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020-07-28T04:23:31.2342558Z ##[debug]    + CategoryInfo          : CloseError: (:) [Set-AzDataFactoryV2LinkedService], FileNotFoundException
2020-07-28T04:23:31.2361626Z ##[debug]    + FullyQualifiedErrorId : Microsoft.Azure.Commands.DataFactoryV2.SetAzureDataFactoryLinkedServiceCommand
2020-07-28T04:23:31.2379154Z ##[debug] 
2020-07-28T04:23:31.2415190Z ##[debug]Script stack trace:
2020-07-28T04:23:31.2479403Z ##[debug]at <ScriptBlock>, D:\a\r1\a\LS_adf\ykfactory\AllADFDeploymentTasks\LinkedService.ps1: line 1
2020-07-28T04:23:31.2532900Z ##[debug]at <ScriptBlock>, D:\a\_temp\a652e51d-54ce-438d-b59a-d8b118516fe9.ps1: line 41
2020-07-28T04:23:31.2553826Z ##[debug]at <ScriptBlock>, <No file>: line 1
2020-07-28T04:23:31.2594489Z ##[debug]Exception:
**2020-07-28T04:23:31.2681432Z ##[debug]S*ystem.IO.**FileNotFoundException**: ./LinkedService.json***
2020-07-28T04:23:31.2716695Z ##[debug]   at Microsoft.Azure.Commands.DataFactoryV2.DataFactoryClient.ReadJsonFileContent(String path)
2020-07-28T04:23:31.2740090Z ##[debug]   at Microsoft.Azure.Commands.DataFactoryV2.SetAzureDataFactoryLinkedServiceCommand.ExecuteCmdlet()
2020-07-28T04:23:31.2760357Z ##[debug]   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
2020-07-28T04:23:31.3196351Z ##[error]./LinkedService.json
2020-07-28T04:23:31.3212488Z ##[debug]Processed: ##vso[task.logissue type=error]./LinkedService.json
2020-07-28T04:23:32.1091196Z ##[debug]Exit code: 1
2020-07-28T04:23:32.1091982Z ##[debug]Leaving Invoke-VstsTool.
2020-07-28T04:23:32.1093065Z ##[error]PowerShell exited with code '1'.
2020-07-28T04:23:32.1094438Z ##[debug]Processed: ##vso[task.logissue type=error]PowerShell exited with code '1'.
2020-07-28T04:23:32.1106224Z ##[debug]Processed: ##vso[task.complete result=Failed]Error detected
2020-07-28T04:23:32.1107726Z ##[debug]Loading module from path 'D:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62.173.0\ps_modules\VstsAzureHelpers_\VstsAzureHelpers_.psm1'.
2020-07-28T04:23:32.1108852Z ##[debug]$OVER[enter image description here][1]

最新错误 - enter image description here 2020-07-28T14:12:59.1777082Z ##[debug]错误记录: 2020-07-28T14:12:59.2606789Z ##[调试]Set-AzDataFactoryV2LinkedService : D:\a\r1\a\LinkedService.json 2020-07-28T14:12:59.2614645Z ##[调试]在 D:\a\r1\a\LS_adf\ykfactory\AllADFDeploymentTasks\LinkedService.ps1:7 char:1 2020-07-28T14:12:59.2641183Z ##[调试]+ Set-AzDataFactoryV2LinkedService -DataFactoryName“DataFlowADFVNet”` 2020-07-28T14:12:59.2665039Z ##[调试]+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2020-07-28T14:12:59.2686771Z ##[调试] + CategoryInfo : CloseError: (:) [Set-AzDataFactoryV2LinkedService], FileNotFoundException 2020-07-28T14:12:59.2731339Z ##[调试] + FullyQualifiedErrorId : Microsoft.Azure.Commands.DataFactoryV2.SetAzureDataFactoryLinkedServiceCommand 2020-07-28T14:12:59.2746815Z ##[调试] 2020-07-28T14:12:59.2791357Z ##[调试]脚本堆栈跟踪: 2020-07-28T14:12:59.2841187Z ##[调试]at , D:\a\r1\a\LS_adf\ykfactory\AllADFDeploymentTasks\LinkedService.ps1: 第 7 行 2020-07-28T14:12:59.2894685Z ##[调试]at,D:\a_temp3f2897-4445-4797-b8c4-62e1fbc3c46a.ps1:第 41 行 2020-07-28T14:12:59.2915479Z ##[调试]在:第 1 行 2020-07-28T14:12:59.2931046Z ##[调试]异常: 2020-07-28T14:12:59.3013273Z ##[调试]System.IO.FileNotFoundException: D:\a\r1\a\LinkedService.json 2020-07-28T14:12:59.3039882Z ##[debug] at Microsoft.Azure.Commands.DataFactoryV2.DataFactoryClient.ReadJsonFileContent(字符串路径) 2020-07-28T14:12:59.3062765Z ##[调试] 在 Microsoft.Azure.Commands.DataFactoryV2.SetAzureDataFactoryLinkedServiceCommand.ExecuteCmdlet() 2020-07-28T14:12:59.3082130Z ##[调试] Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() 2020-07-28T14:12:59.3469116Z ##[错误]D:\a\r1\a\LinkedService.json 2020-07-28T14:12:59.3489081Z ##[调试]已处理:##vso[task.logissue 类型=错误]D:\a\r1\a\LinkedService.json 2020-07-28T14:12:59.4029653Z ##[调试]退出代码:1 2020-07-28T14:12:59.4104968Z ##[调试]离开 Invoke-VstsTool。 2020-07-28T14:12:59.4476571Z ##[错误]PowerShell 已退出,代码为“1”。 2020-07-28T14:12:59.4477979Z ##[调试]已处理:##vso[task.logissue type=error]PowerShell 已退出,代码为“1”。 2020-07-28T14:12:59.4575374Z ##[调试]已处理:##vso[task.complete 结果=失败] 检测到错误 2020-07-28T14:12:59.4603727Z ##[调试]从路径 'D:\a_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62.173.0\ps_modules\VstsAzureHelpers_\VstsAzureHelpers_.psm1' 加载模块。 2020-07-28T14:12:59.4744776Z ##[debug]$OVERRIDING $global:DebugPreference 从 'Continue' 到 'SilentlyContinue'。 2020-07-28T14:12:59.4926089Z ##[调试]从以下位置加载资源字符串:D:\a_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62.173.0\ps_modules\VstsAzureHelpers_/module.json 2020-07-28T14:12:59.5854494Z ##[调试]加载了 13 个字符串。

How to provide file path of JSON file kept in azure devops git repository to PowerShell script.Getting file not found exception

我们无法直接使用 powershell 脚本中的预定义变量。

要在 powershell 中使用预定义变量,我们可以使用 inline powershell task 或者我们可以通过 PowerShell 参数传递预定义变量的值:

-pass $(System.DefaultWorkingDirectory)

还有我的测试。ps1:

Param(
 [String]$pass
)

Write-Host "$pass"

结果: