Kagemand Andersen
Kagemand Andersen

Reputation: 1693

Python Azure Functions app won't deploy through Azure Pipeline

I have a small Azure Functions API written in Python. Works locally. I can deploy it to my Azure Function app in my Azure subscription via Visual Studio Code and it works as intended.

However, when I deploy it via a release pipeline in Azure DevOps it doesn't work. I cannot find any errors or anything that signifies that something has gone wrong, but the HTTP trigger do not appear on the Azure Portal page for the Azure Function app, and the API does not appear to be up.

imports in the Python script:

import azure.functions as func
import logging
import base64
import io
import matplotlib.pyplot as plt
import struct

requirements.txt:

azure-functions
matplotlib

Build pipeline YAML (don't think this matters since it's Python, but whatever):

pool:
  vmImage: ubuntu-latest

steps:
- task: UsePythonVersion@0
  displayName: "Set Python version to 3.11"
  inputs:
    versionSpec: '3.11'
    architecture: 'x64'

- bash: |
    if [ -f extensions.csproj ]
    then
        dotnet build extensions.csproj --output ./bin
    fi
    pip install --target="./.python_packages/lib/site-packages" -r ./Solutions/FunctionApp/requirements.txt

- task: ArchiveFiles@2
  displayName: "Archive files"
  inputs:
    rootFolderOrFile: "$(System.DefaultWorkingDirectory)/Solutions/FunctionApp"
    includeRootFolder: false
    archiveFile: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip"

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip'
    artifactName: 'drop'

Release Pipeline YAML:

steps:
- task: AzureFunctionApp@2
  displayName: 'Azure Function App Deploy: my-func-weu-app'
  inputs:
    connectedServiceNameARM: 'gnh-quantum-development'
    appType: functionAppLinux
    appName: 'my-func-weu-app'

Given that it works both locally and when I deploy via Visual Studio Code I assume the problem lies in the release pipeline, but I cannot figure out what the problem could be.

Almost forgot. When I deploy via Azure DevOps pipeline I can see in the 'App Files' tab that it has uploaded the files (function_app.py, requirements.txt, .gitignore, .funcignore, and host.json).

Upvotes: 0

Views: 465

Answers (1)

Kagemand Andersen
Kagemand Andersen

Reputation: 1693

Okay, so it turns out I just wasn't paying attention. I thought the build pipeline didn't really matter outside of checking requirements and doing testing because it is a Python app, but it does. I needed to install the packages and include them in my artifact.

So, this:

- bash: |
    if [ -f extensions.csproj ]
    then
        dotnet build extensions.csproj --output ./bin
    fi
    pip install --target="./.python_packages/lib/site-packages" -r ./Solutions/FunctionApp/requirements.txt

Should have been this:

- bash: |
    if [ -f extensions.csproj ]
    then
        dotnet build extensions.csproj --output ./bin
    fi
    pip install --target="./Solutions/FunctionApp/.python_packages/lib/site-packages" -r ./Solutions/FunctionApp/requirements.txt

I was installing the packages, but set the build target to a directory I wasn't including in the artifact.

Thanks for the rubber-ducking, StackOverflow. Hope this helps someone else in the same situation.

Upvotes: 5

Related Questions