gpt4 book ai didi

azure - 带有 CiCd 管道的 Python Azure 函数 : ModuleNotFound Error

转载 作者:行者123 更新时间:2023-12-03 02:09:38 24 4
gpt4 key购买 nike

你好,
我在使用 CICD 管道部署 azure python 函数时遇到错误。错误是ModuleNotFoundError:没有名为“azure.servicebus”的模块。但情况是,在 CICD 管道上构建包时已经安装了服务总线模块。
使用 vscode 或 azure cli 直接部署时,Function 应用运行良好,没有任何错误。

    工作环境和功能应用程序python版本 - 3.7Azure 函数应用版本 - 3.xCICD 管道代理规范 - ubuntu-latest
错误-
Error

执行函数时会发生此错误。该函数应用程序是使用 CiCd 管道部署的,所有依赖项都包含在 requests.txt 中,如下所示。

requirements.txt
requirements.txt

这是管道构建 bash 脚本
bash script

有谁可以帮忙吗?

最佳答案

我能够重现您的问题:

enter image description here

enter image description here

我可以解决这个问题:

enter image description here

我知道你在做什么。创建虚拟环境,激活虚拟环境,安装python包到虚拟环境...

并且您提到 VS Code/CLI 部署没有问题。

是的,正如您所观察到的,所有内容都应该成功安装到虚拟环境中。

So Why?

原因是VS Code Deploy和CLI部署都与虚拟环境没有任何关系,这些部署方法只关心requirements.txt文件,不检查其他文件。

并且,您所做的这些操作仅适用于当前代理计算机,您部署到的Azure功能应用程序是另一种情况。这是一台新机器,一个新环境。

所以你只需要像这样简单地设计管道:

trigger:
- none
pool:
VMAS
steps:
- task: AzurePowerShell@5
inputs:
azureSubscription: 'testbowman_in_AAD'
ScriptType: 'InlineScript'
Inline: 'func azure functionapp publish <Your FunctionApp Name> --build remote'
azurePowerShellVersion: 'LatestVersion'

VS Code和CLI的工作原理

https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level#remote-build

By default, Azure Functions Core Tools requests a remote build whenyou use the following func azure functionapp publish command topublish your Python project to Azure. Replace <APP_NAME> with the nameof your function app in Azure.

The Azure Functions extension for Visual Studio Code also requests aremote build by default.

关于azure - 带有 CiCd 管道的 Python Azure 函数 : ModuleNotFound Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73729962/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com