skip to Main Content

Hello,
I got an error while deploying azure python function using cicd pipeline. The error is ModuleNotFoundError: No module named 'azure.servicebus'. But the case is, service-bus module already installing while building the package on cicd pipeline.
When direct deploying using vscode or azure cli, the Function app works fine without any error.

    working environment and function app python version – 3.7

    azure function app version – 3.x

    cicd pipeline agent specification – ubuntu-latest

Error –
Error

This error occurs when a function is executed. The function app was deployed using the CiCd pipeline and all dependencies are include in requirements.txt as shown below.

requirements.txt
requirements.txt

Here is the pipeline build bash script
bash script

Could anyone please help?

2

Answers


  1. I am able to reproduce your issue:

    enter image description here

    enter image description here

    And I can fix this issue:

    enter image description here

    I know what you are doing. Create virtual environment, active virtual environment, install python packages to the virtual environment…

    And you mentioned VS Code/CLI deploy is no problem.

    Yes, as you observe, everything should be installed successfully to the virtual environment.

    So Why?

    The reason is both of VS Code Deploy and CLI deploy doesn’t have any relationship with virtual environment, these deployment method only care the requirements.txt file, they don’t check others.

    And, those operations you done is only work on current agent machine, azure function app you deploy to is another situation. It is a new machine, a new environment.

    So you just need to simply design the pipeline like this:

    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'
    

    Working principle of VS Code and 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 when
    you use the following func azure functionapp publish command to
    publish your Python project to Azure. Replace <APP_NAME> with the name
    of your function app in Azure.

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

    Login or Signup to reply.
  2. This help me to resolve the issue
    Instead of pip install -r requirements.txt use pip install –target="./.python_packages/lib/site-packages" -r ./requirements.txt

    https://github.com/Azure/azure-functions-python-worker/issues/708

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search