我有一个 PowerShell 脚本,我想在函数应用程序中运行,但是当我运行该脚本进行测试时,它开始下载依赖项,然后出现此错误:
FailureException:无法安装函数应用依赖项。错误:“无法安装函数应用依赖项。错误:“正在运行的命令已停止,因为首选项变量“ErrorActionPreference”或通用参数设置为“停止”:无法保存模块“Az”。”堆栈:位于 Microsoft.Azure.Functions.PowerShellWorker.DependencyManagement.DependencyManager.WaitOnDependencyInstallationTask( )
我不知道为什么无法安装依赖项。有关更多上下文,请参阅我的
host.JSON
文件:
{
"version":"2.0",
"functionTimeout":"00:10:00",
"managedDependency":{
"enabled":true
},
"extensionBundle":{
"id":"Microsoft.Azure.Functions.ExtensionBundle",
"version":"[4.*, 5.0.0)"
}
}
这是我的
requirements.psd1
:
# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
# To use the Az module in your function app, please uncomment the line below.
'Az' = '13.*'
'PnP.PowerShell' = '2.12.0'
}
我也在脚本中导入了模块,并且检查了 kudu 中的文件,有时它会从 az 库安装一些模块,但会丢失很多模块,有时会完全失败,并且 kudu 仅显示 requests.psd1 文件。
使用高级定价计划和运行时堆栈创建 Azure 函数应用程序
Powershell 7.4 version
.
要求.ps1:
@{
'Az' = '13.*'
'PnP.PowerShell' = '2.12.0'
}
主机.json:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"managedDependency": {
"enabled": true
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
已将功能部署到Azure:
能够成功运行Portal中部署的功能:
2025-01-07T07:01:56Z [Verbose] AuthenticationScheme: WebJobsAuthLevel was successfully authenticated.
2025-01-07T07:01:56Z [Verbose] AuthenticationScheme: Bearer was not authenticated.
2025-01-07T07:01:56Z [Verbose] Authorization was successful.
2025-01-07T07:01:56Z [Information] Executing 'Functions.HttpTrigger' (Reason='This function was programmatically called via the host APIs.', Id=2a08447d-fa97-4322-9a6a-6112dbc62e3f)
2025-01-07T07:01:56Z [Verbose] Sending invocation id: '2a08447d-fa97-4322-9a6a-6112dbc62e3f
2025-01-07T07:01:56Z [Verbose] Posting invocation id:2a08447d-fa97-4322-9a6a-6112dbc62e3f on workerId:fe54a398-cf82-48e5-90bc-b871e0222496
2025-01-07T07:01:56Z [Information] INFORMATION: PowerShell HTTP trigger function processed a request.
2025-01-07T07:01:57Z [Information] Executed 'Functions.HttpTrigger' (Succeeded, Id=2a08447d-fa97-4322-9a6a-6112dbc62e3f, Duration=400ms)