You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Pipeline部署Python函数应用异常:指向不存在Blob

问题描述

刚接触YAML,搭建了面向Linux的Python函数应用CI/CD Pipeline,CI环节运行正常,但CD环节显示部署成功后,函数应用内无任何内容,且Pipeline输出显示调用一个不存在的Blob存储文件。尝试手动修改WEBSITE_RUN_FROM_PACKAGE配置项,但刷新函数应用后该配置自动复原。相关配置及日志如下:

YAML配置

# Python Function App to Linux on Azure
# Build a Python function app and deploy it to Azure as a Linux function app.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/python

trigger:
- master

variables:
  # Azure Resource Manager connection created during pipeline creation
  azureSubscription: 'ab1c86d0-0d0c-4029-913b-e5483df967b2'

  # Function app name
  functionAppName: 'categoriserfunctionapp'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

  # Working Directory
  workingDirectory: ''

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.6 # Functions V2 supports Python 3.6 as of today
        architecture: 'x64'

    - 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: "$(System.DefaultWorkingDirectory)"
        includeRootFolder: false
        archiveType: zip
        archiveFile: "$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip"
        replaceExistingArchive: true

    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(System.DefaultWorkingDirectory)/$(Build.BuildId).zip'
        artifactName: 'drop'
        
- stage: Deploy
  displayName: Deploy stage
  dependsOn: Build
  condition: succeeded()

  jobs:
  - deployment: Deploy
    displayName: Deploy
    environment: 'test'
    pool:
      vmImage: 'windows-latest'

    strategy:
      runOnce:
        deploy:

          steps:
          - task: DownloadPipelineArtifact@2
            displayName: 'Download Pipeline Artifact'
            inputs:
              buildType: 'current'
              artifactName: 'drop'
              targetPath: '$(Pipeline.Workspace)/drop/'
          - task: AzureFunctionApp@1
            inputs:
              azureSubscription: 'Visual Studio Enterprise Subscription – MPN (f1f3e234-557b-4acd-b353-2ff89c547e49)'
              appType: 'functionAppLinux'
              appName: 'categoriserfunctionapp'
              package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
              runtimeStack: 'PYTHON|3.9'

CD环节执行日志

2022-09-27T15:59:26.6330661Z ##[section]Starting: AzureFunctionApp
2022-09-27T15:59:26.6442433Z ==============================================================================
2022-09-27T15:59:26.6442718Z Task         : Azure Functions
2022-09-27T15:59:26.6443009Z Description  : Update a function app with .NET, Python, JavaScript, PowerShell, Java based web applications
2022-09-27T15:59:26.6443282Z Version      : 1.208.2
2022-09-27T15:59:26.6443454Z Author       : Microsoft Corporation
2022-09-27T15:59:26.6443686Z Help         : https://aka.ms/azurefunctiontroubleshooting
2022-09-27T15:59:26.6443957Z ==============================================================================
2022-09-27T15:59:27.4092341Z Got service connection details for Azure App Service:'categoriserfunctionapp'
2022-09-27T15:59:30.9793711Z Trying to update App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"https://categoriserfunc9c44.blob.core.windows.net/azure-pipelines-deploy/package_1664294369833.zip?***"}
2022-09-27T15:59:32.4412565Z Updated App Service Application settings.
2022-09-27T15:59:32.4414182Z Updated WEBSITE_RUN_FROM_PACKAGE Application setting to https://categoriserfunc9c44.blob.core.windows.net/azure-pipelines-deploy/package_1664294369833.zip?***
2022-09-27T15:59:37.4527980Z Syncing triggers for function app
2022-09-27T15:59:39.3782043Z Sync triggers for function app completed successfully
2022-09-27T15:59:41.0691225Z Successfully added release annotation to the Application Insight : categoriserfunctionapp
2022-09-27T15:59:41.3968439Z App Service Application URL: https://categoriserfunctionapp.azurewebsites.net
2022-09-27T15:59:41.4063927Z ##[section]Finishing: AzureFunctionApp

解决思路

  • 统一Python版本:Build阶段用的Python 3.6,Deploy阶段指定的runtimeStack是PYTHON|3.9,版本不匹配会导致部署后函数无法正常加载。将Build阶段的Python版本改为3.9,或者Deploy阶段的runtimeStack改为3.6,保持两者一致。
  • 修正打包范围:当前ArchiveFiles任务打包了$(System.DefaultWorkingDirectory)下所有文件,可能包含无关的临时文件。应只打包函数应用的核心代码目录,比如函数代码在$(System.DefaultWorkingDirectory)/func_app下,就把rootFolderOrFile改成该路径,避免冗余内容干扰部署。
  • 排查Blob存储问题:日志中的Blob URL无法访问,先确认对应存储账户、容器是否存在,检查Pipeline服务连接是否有该Blob的访问权限,也可以手动上传测试包到容器,修改WEBSITE_RUN_FROM_PACKAGE指向测试包,验证是否能加载函数。
  • 阻止配置自动还原:手动修改配置后自动复原,可能是其他自动化工具(如其他Pipeline、部署槽同步)在操作配置。先检查是否有其他自动化任务,或者停止函数应用后再修改配置,观察是否还会被还原。
  • 更换Deploy代理镜像:Deploy阶段用windows-latest代理,而函数应用是Linux版本,换成ubuntu-latest代理可避免跨系统部署的兼容性问题。
  • 验证部署包路径:在DownloadPipelineArtifact任务后添加bash步骤,打印$(Pipeline.Workspace)/drop/下的文件列表,确认zip包是否存在,同时检查$(Build.BuildId)在Deploy阶段是否能正确获取到Build阶段的ID。

内容的提问来源于stack exchange,提问作者howlieT

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 05:40:31