最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - function app deployed through azure devops pipeline not recognizing the function - Stack Overflow

programmeradmin6浏览0评论

main issue to have context: the function isnt recognized by the function app and listed in the functions list so i have a function app which should include a timer triggered python function which i stored in azure devops repos unter the following structure : Function_App/

│── host.json

│── requirements.txt

│── leanjira_timer_sync/

│ ├── leansyncjira.py

│ ├── function.json

then im archiving and deploying it using a pipeline and this is the yaml file part responsible for that :

stage: Deploy_Function_App
  displayName: "Deploy Function App"
  # dependsOn: Deploy_Logic_App
  jobs:
  - job: DeployFunctionApp
    displayName: "Deploy Azure Function"
    steps:
    - task: UsePythonVersion@0
      displayName: "Use Python 3.11"
      inputs:
        versionSpec: '3.11'

    - script: |
        ls -l
        ls -R
        python -m venv .venv
        source .venv/bin/activate
        python -m pip install --upgrade pip
        pip install -r $(System.DefaultWorkingDirectory)/JiraSync/Function_App/requirements.txt
      displayName: "Install Dependencies in Virtual Environment"

    - task: ArchiveFiles@2
      displayName: "Archive Function App Code"
      inputs:
        rootFolderOrFile: "$(System.DefaultWorkingDirectory)/JiraSync/Function_App"
        includeRootFolder: true # Only archive the function content, not the parent folder
        archiveType: "zip"
        archiveFile: "$(Build.ArtifactStagingDirectory)/JiraSync/functionapp.zip"
        replaceExistingArchive: true
- task: AzureFunctionApp@1
      displayName: "Deploy Function App"
      inputs:
        azureSubscription: $(azureSubscription)
        appType: "functionAppLinux"
        appName: $(functionAppName)
        package: "$(Build.ArtifactStagingDirectory)/JiraSync/functionapp.zip"
        deploymentMode: "Incremental"

the deployment is working but in the app files in azure only the host.json and requirements.txt files are there the subfolder is not there. and i tried to use the python V2 programming model (with decorators) instead of using the subfolder and a function.json like this :

app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
@app.route(route="leanjira_script", methods=["GET", "POST"])
def leansyncjira_script(req: func.HttpRequest) -> func.HttpResponse:
  logging.info('Python HTTP trigger function processed a request.')

but i also tried the function.json way and it is not uploading the subfolder of the code and function.json (they dont appear in the app files in the function app) . but if i deploy the first version with the bindings above ^ through VS Code then it works and it is recognized.

main issue to have context: the function isnt recognized by the function app and listed in the functions list so i have a function app which should include a timer triggered python function which i stored in azure devops repos unter the following structure : Function_App/

│── host.json

│── requirements.txt

│── leanjira_timer_sync/

│ ├── leansyncjira.py

│ ├── function.json

then im archiving and deploying it using a pipeline and this is the yaml file part responsible for that :

stage: Deploy_Function_App
  displayName: "Deploy Function App"
  # dependsOn: Deploy_Logic_App
  jobs:
  - job: DeployFunctionApp
    displayName: "Deploy Azure Function"
    steps:
    - task: UsePythonVersion@0
      displayName: "Use Python 3.11"
      inputs:
        versionSpec: '3.11'

    - script: |
        ls -l
        ls -R
        python -m venv .venv
        source .venv/bin/activate
        python -m pip install --upgrade pip
        pip install -r $(System.DefaultWorkingDirectory)/JiraSync/Function_App/requirements.txt
      displayName: "Install Dependencies in Virtual Environment"

    - task: ArchiveFiles@2
      displayName: "Archive Function App Code"
      inputs:
        rootFolderOrFile: "$(System.DefaultWorkingDirectory)/JiraSync/Function_App"
        includeRootFolder: true # Only archive the function content, not the parent folder
        archiveType: "zip"
        archiveFile: "$(Build.ArtifactStagingDirectory)/JiraSync/functionapp.zip"
        replaceExistingArchive: true
- task: AzureFunctionApp@1
      displayName: "Deploy Function App"
      inputs:
        azureSubscription: $(azureSubscription)
        appType: "functionAppLinux"
        appName: $(functionAppName)
        package: "$(Build.ArtifactStagingDirectory)/JiraSync/functionapp.zip"
        deploymentMode: "Incremental"

the deployment is working but in the app files in azure only the host.json and requirements.txt files are there the subfolder is not there. and i tried to use the python V2 programming model (with decorators) instead of using the subfolder and a function.json like this :

app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
@app.route(route="leanjira_script", methods=["GET", "POST"])
def leansyncjira_script(req: func.HttpRequest) -> func.HttpResponse:
  logging.info('Python HTTP trigger function processed a request.')

but i also tried the function.json way and it is not uploading the subfolder of the code and function.json (they dont appear in the app files in the function app) . but if i deploy the first version with the bindings above ^ through VS Code then it works and it is recognized.

Share Improve this question asked Mar 27 at 9:18 confusedJuniorconfusedJunior 451 silver badge5 bronze badges 1
  • The possible reason of this issue is that the function app isn't at the root directory. See: learn.microsoft/en-us/azure/azure-functions/… – Bright Ran-MSFT Commented Mar 27 at 9:58
Add a comment  | 

1 Answer 1

Reset to default 0

The possible reason of this issue is that the function app isn't at the root directory.

On the ArchiveFiles@2 task in your pipeline, change the set to "includeRootFolder: false".

    . . .

    - task: ArchiveFiles@2
      displayName: "Archive Function App Code"
      inputs:
        rootFolderOrFile: "$(System.DefaultWorkingDirectory)/JiraSync/Function_App"
        includeRootFolder: false
        archiveType: "zip"
        archiveFile: "$(Build.ArtifactStagingDirectory)/JiraSync/functionapp.zip"
        replaceExistingArchive: true

    . . .

Documentations as reference:

  • Continuous delivery with Azure Pipelines
  • Functions not found after deployment

UPDATE:

Another point you need to check is ensure the 'pip install' command has installed the dependencies into the directory ".python_packages/lib/site-packages". You can use the option --target="{root}/.python_packages/lib/site-packages" on the 'pip install' command to specify the directory.

For your case, change the like as below.

. . .

steps:
. . .

- bash: |
    ls -l
    ls -R
    python -m venv .venv
    source .venv/bin/activate
    python -m pip install --upgrade pip
    pip install \
    --target="$(System.DefaultWorkingDirectory)/JiraSync/Function_App/.python_packages/lib/site-packages" \
    -r $(System.DefaultWorkingDirectory)/JiraSync/Function_App/requirements.txt
  displayName: "Install Dependencies in Virtual Environment"

- task: ArchiveFiles@2
  displayName: "Archive Function App Code"
  inputs:
    rootFolderOrFile: "$(System.DefaultWorkingDirectory)/JiraSync/Function_App"
    includeRootFolder: false
    archiveType: "zip"
    archiveFile: "$(Build.ArtifactStagingDirectory)/JiraSync/functionapp.zip"
    replaceExistingArchive: true

. . .
发布评论

评论列表(0)

  1. 暂无评论