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

Azure Pipeline运行中wheel(.whl)文件生成位置及部署问题咨询

问题分析与解决方案

核心问题

  1. 阶段间产物不共享:Azure Pipeline的Build和Deploy阶段是独立运行在不同代理节点上的,默认不会保留上一阶段生成的文件,所以你在Build阶段生成的wheel到Deploy阶段就找不到了,只能重复构建。
  2. Wheel生成路径错误:当你在仓库根目录执行python src/databricks/setup.py bdist_wheel时,bdist_wheel会在**当前工作目录(仓库根目录)**生成dist文件夹,而不是src/databricks子目录下,你后续指定的src/databricks/dist/...路径根本不存在,自然无法复制到DBFS。
  3. 冗余重复构建:Deploy阶段没必要重复执行构建wheel的操作,完全可以复用Build阶段的产物。

修正后的Pipeline配置

stages:
  - stage: Build
    jobs: 
    - job: BuildWheel
      steps:
      - task: Bash@3
        inputs:
          targetType: 'inline'
          script: | 
            echo 'install/update pip and wheel'
            python -m pip install --upgrade pip wheel 
            echo 'building wheel file'
            python src/databricks/setup.py bdist_wheel
            # 可选:查看当前目录结构,确认wheel生成位置
            ls -R $(Build.SourcesDirectory)
        displayName: 'Build updated wheel file'
      # 发布构建产物,供后续阶段使用
      - task: PublishPipelineArtifact@1
        inputs:
          targetPath: '$(Build.SourcesDirectory)/dist'
          artifact: 'wheel-artifact'
          publishLocation: 'Container'
        displayName: 'Publish wheel artifact'

  - stage: Deploy
    jobs:
    - job: DeployToDBFS
      steps:
      # 下载Build阶段发布的wheel产物
      - task: DownloadPipelineArtifact@2
        inputs:
          artifact: 'wheel-artifact'
          path: '$(Build.SourcesDirectory)/dist'
        displayName: 'Download wheel artifact'
      
      - script: |
          echo 'installing databricks-cli'
          python -m pip install --upgrade databricks-cli
        displayName: 'Install Databricks CLI'                    
      
      - script: |
          echo 'copying wheel file'
          # 路径修正为根目录下的dist文件夹
          databricks fs cp --overwrite dist/library-0.0.2-py3-none-any.whl dbfs:/FileStore/whl
          echo 'copying main.py'
          databricks fs cp --overwrite src/databricks/main.py dbfs:/FileStore/whl
        env:
          DATABRICKS_HOST: $(DATABRICKS_HOST)
          DATABRICKS_TOKEN: $(DATABRICKS_TOKEN)
        displayName: 'Copy wheel file and main.py to DBFS'

关键说明

  • 产物共享机制:通过PublishPipelineArtifact和DownloadPipelineArtifact任务,实现不同阶段之间的文件传递,避免重复构建。
  • 路径验证:如果不确定wheel的生成位置,可以在Build阶段的脚本中加入ls -R $(Build.SourcesDirectory)(Linux代理)或dir /s $(Build.SourcesDirectory)(Windows代理),直接查看所有文件的目录结构,确认dist文件夹的位置。
  • 版本号注意:如果你的wheel版本号会变动,建议用通配符匹配文件,比如dist/library-*.whl,避免每次版本更新都要修改YAML中的文件名。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 11:20:35