ModuleNotFoundError: No module named '{custom package name}'. Cannot find module.
ModuleNotFoundError occurs when your package is not listed in the requirements.txt of your Function App, If you want to install your package separately, You will have to add apt-get package-name command or pip install package-name command in the startup command section of Azure Function DevOps task seperately.
Startup command in yaml:-
- task: AzureFunctionApp@1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: 'xxxxxx (xxxxxx)'
appType: 'functionAppLinux'
appName: 'siliconfuncv2'
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
startUpCommand: 'apt-get update apt-get install libgstreamer1.0-0 libunwind-dev gstreamer1.0-pulseaudio'
There are two ways you can install Custom packages in your Linux Function app.
Refer my SO answer1 where I have added the Custom packages in the Source code Folder and then added the Folder name as path in the requirements.txt while Deployment of the Web App the packages inside the Folder are added automatically. You can use same concept to Deploy custom package to your Function App.
Refer SO answer2 where you can upload your custom packages in Github and then use this git+https://[email protected]/sid24desai/pycode.git@main url with your Github PAT token/githuborg/repository/ in your requirements.txt like below:-
This is my requirements.txt:-
azure-functions
git+https://[email protected]/sid24desai/pycode.git@main
My Azure Devops yaml pipeline:-
trigger:
- master
variables:
azureSubscription: 'xxxxxxxx97cb2a7'
functionAppName: 'siliconfunc65'
vmImageName: 'ubuntu-latest'
workingDirectory: '$(System.DefaultWorkingDirectory)'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
fi
workingDirectory: $(workingDirectory)
displayName: 'Build extensions'
- task: UsePythonVersion@0
displayName: 'Use Python 3.6'
inputs:
versionSpec: 3.10
- bash: |
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
workingDirectory: $(workingDirectory)
displayName: 'Install application dependencies'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(workingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: 'development'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp@1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: 'xxxxx subscription (xxxxxxxb2a7)'
appType: 'functionAppLinux'
appName: '$(functionAppName)'
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'

Additional Reference:-
Azure Function Deployment using CI-CD pipeline Differing from VsCode Deployment - Stack Overflow My SO answer