Azure Pipeline Deploy not working anymore on Azure Functions Python

Rodrigo Doering Neves 0 Reputation points
2024-02-12T21:17:40.7066667+00:00

Timestamp: 12 /02/2024 (dd/mm/yyy) So, basically, Azure Functions is deprecating older versions of Python, so I decided to create a new azure functions app and implement the same CI/CD logic I've been using without errors for the past year, but now with python 3.9 version. Unfortunately, I can't make it work. It raises module not found error, something that was fixed in previous versions by adding --target flag in pip install command.

The first yaml we attempted is:

trigger:
- test-branch

variables:
  azureSubscription: 'xxxxxxxxxxxxxxxxxxxxx'
  functionAppName: 'new function app'
  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 --output ./bin
        fi
      workingDirectory: $(workingDirectory)
      displayName: 'Build extensions'

    - task: UsePythonVersion@0
      displayName: 'Use Python 3.9'
      inputs:
        versionSpec: 3.9 

    - bash: |
        python -m venv .venv
        source .venv/bin/activate
        pip install --upgrade pip
        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: '$(azureSubscription)'
              appType: functionAppLinux
              appName: $(functionAppName)
              package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'

So, I read the documentation, turns out that template is actually a bit outdated, and the new one would look like this:

trigger:
- test-branch

variables:
  azureSubscription: 'xxxxxxxxxxxxxxxx'
  functionAppName: 'new function app'
  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 --output ./bin
        fi
        pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
      workingDirectory: $(workingDirectory)
      displayName: 'Build extensions'

    - 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: '$(azureSubscription)'
              appType: functionAppLinux
              appName: $(functionAppName)
              package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'

Tried then to redeploy, it ran smooth with no errors, however, when I check my function app, there is no code at all, like it can't reach the package I just deployed like the printscreen bellow: evid1 Right now I'm clueless. This are the two major suggestions in the community right now, but none are working as expected for me. One thing I noticed is that, if I download and expect the app files, the overall structure looks ok, with a python_package folder and the rest of my functions, host.json and etc. NOTE: I'm using the new template as stated in documentation from newer python versions (version 3.9) however still using python programming model v1. I need some help, Thanks in advance, Rodrigo

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,007 questions
{count} votes