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

Azure Python Web应用CI/CD Pipeline报错:未找到指定压缩包

问题排查与修复方案

错误根源分析

你遇到的Error: No package found with specified pattern: D:\a\r1\a\**\drop.zip错误,核心是部署任务找不到正确的压缩包路径,同时你的Pipeline配置存在逻辑冗余和路径错误:

1. 路径匹配失效+部署逻辑混乱

你在Build阶段的任务里,下载制品后压缩包实际存放在$(System.DefaultWorkingDirectory)/drop/$(Build.BuildId).zip,但给AzureWebApp@1配置的路径是$(System.DefaultWorkingDirectory)/**/*.zip,无法精准匹配到目标文件。同时你已经定义了单独的Deploy阶段,却在Build阶段重复添加部署任务,完全没必要。

2. 其他潜在问题

  • 变量projectRoot用了Windows风格路径C:\codes\StudentWebApp,但你配置的代理是ubuntu-latest(Linux系统),后续使用该变量会触发路径错误。
  • pip install setup命令无效,setup不是合法的PyPI包名,若项目有setup.py,应改为pip install -e .,否则直接安装依赖即可。

修复后的Pipeline配置

# Python to Linux Web App on Azure
# Build your Python project and deploy it to Azure as a Linux Web App.
# Change the python version to one that is appropriate for your application.

trigger:
- master

variables:
  # Azure Resource Manager connection created during pipeline creation
  azureServiceConnectionId: '*****************************'

  # Agent VM image name
  vmImageName: ubuntu-latest

  # Environment name
  environmentName: StudentWebappDev

  # Project root folder. Point to the folder containing manage.py file.
  projectRoot: /codes/StudentWebApp

  # Python version: 3.7
  pythonVersion: 3.7

stages:
- stage: Build
  displayName: Build stage
  jobs:
  - job: BuildJob
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: UsePythonVersion@0
      inputs:
        versionSpec: '$(pythonVersion)'
      displayName: 'Use Python $(pythonVersion)'

    - script: |
        python -m venv antenv
        source antenv/bin/activate
        python -m pip install --upgrade pip
        # 替换无效的pip install setup,若有setup.py可改为pip install -e .
        pip install -r requirements.txt
        pip freeze > requirements.txt
      workingDirectory: $(System.DefaultWorkingDirectory)
      displayName: "Install requirements"

    - task: ArchiveFiles@2
      displayName: 'Archive files'
      inputs:
        rootFolderOrFile: $(System.DefaultWorkingDirectory)
        includeRootFolder: false
        archiveType: zip
        archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
        replaceExistingArchive: true

    - task: PublishBuildArtifacts@1
      inputs:
        pathtoPublish: '$(Build.ArtifactStagingDirectory)'
        artifactName: drop
        publishLocation: 'Container'
      displayName: 'Publish build artifacts'

- stage: Deploy
  displayName: 'Deploy Web App'
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: DeploymentJob
    pool:
      vmImage: $(vmImageName)
    environment: $(environmentName)
    strategy:
      runOnce:
        deploy:
          steps:
          - task: UsePythonVersion@0
            inputs:
              versionSpec: '$(pythonVersion)'
            displayName: 'Use Python version'

          - task: DownloadBuildArtifacts@0
            inputs:
              artifactName: drop
              downloadPath: '$(System.DefaultWorkingDirectory)'
            displayName: 'Download build artifacts'

          - task: AzureWebApp@1
            inputs:
              package: '$(System.DefaultWorkingDirectory)/drop/*.zip'
              azureSubscription: '$(azureServiceConnectionId)'
              appName: AppServiceStudentWeb
            displayName: 'Deploy to Azure Web App'

关键修复点说明

  1. 分离CI/CD阶段:把部署任务移到专门的Deploy阶段,符合构建与部署分离的原则,避免逻辑混乱。
  2. 修正压缩包路径:部署阶段下载制品后,使用$(System.DefaultWorkingDirectory)/drop/*.zip精准匹配目标压缩包。
  3. 统一路径格式:将projectRoot改为Linux风格路径,适配ubuntu代理环境。
  4. 修复依赖安装命令:替换无效的pip install setup,确保依赖安装正常执行。
  5. 复用变量配置:统一使用预定义变量,减少硬编码,提升配置可维护性。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 01:30:30