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

Azure DevOps流水线下载构件失败:构件myapp未找到

问题

我有一个可正常运行的Azure DevOps构建流水线,配置如下:

pool:
vmImage: 'windows-latest'
steps:
- script: |
    dotnet restore
    dotnet build --configuration Release
- task: DotNetCoreCLI@2
  inputs:
    command: publish
    arguments: '--configuration Release --output publish_output'
    projects: 'MyProject/*.csproj'
    publishWebProjects: false
    modifyOutputPath: false
    zipAfterPublish: false
- task: ArchiveFiles@2
  displayName: "Archive files"
  inputs:
    rootFolderOrFile: "$(System.DefaultWorkingDirectory)/publish_output"
    includeRootFolder: false
    archiveFile: "$(System.DefaultWorkingDirectory)/myapp.zip"
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(System.DefaultWorkingDirectory)/myapp.zip'
    artifactName: 'myapp'

该流水线运行正常,构建日志显示构件已上传:

Upload 'D:\a\1\s\myapp.zip' to file container: '#/29596927/myapp'

但对应的发布流水线在DownloadBuildArtifacts任务阶段失败,报错:

##[error]Artifact myapp was not found for build xy.

发布流水线配置如下:

trigger:
- main

variables:
  azureSubscription: MySubscription
  appName: myAppName
  vmImageName: 'ubuntu-latest'

steps: 

- task: DownloadBuildArtifacts@1
  inputs:
    buildType: 'current'
    downloadType: 'single'
    artifactName: 'myapp'
    downloadPath: '$(Build.ArtifactsDirectory)'
- task: AzureFunctionApp@1 # Add this at the end of your file
  inputs:
    azureSubscription:  $(azureSubscription)
    appType: functionApp # default is functionApp
    appName: $(appName)
    package: $(Build.ArtifactsDirectory)/**/*.zip

即使启用流水线运行分析,也找不到DownloadBuildArtifacts任务搜索构件的路径信息,请问是否需要替换Build.ArtifactsDirectory,还是存在其他问题?

解决方案
  • 修正buildType参数配置
    发布流水线中DownloadBuildArtifacts@1的buildType: 'current'仅适用于发布流水线与构建流水线属于同一管道的场景。如果你的构建和发布是两条独立管道,必须将buildType改为specific,并补充构建流水线的定位信息,示例配置:

    - task: DownloadBuildArtifacts@1
      inputs:
        buildType: 'specific'
        projectName: '你的项目名称'
        pipeline: '构建流水线的ID'
        buildVersionToDownload: 'latest'
        downloadType: 'single'
        artifactName: 'myapp'
        downloadPath: '$(Build.ArtifactsDirectory)'
    
  • 排查构件名称大小写匹配
    Azure DevOps的构件名称区分大小写,仔细核对构建日志中的构件名与发布任务中指定的artifactName是否完全一致(包括大小写)。

  • 改用更灵活的DownloadPipelineArtifact@2任务
    DownloadBuildArtifacts@1属于旧版任务,推荐替换为DownloadPipelineArtifact@2,它支持跨管道、跨项目的构件下载,定位逻辑更清晰,示例配置:

    - task: DownloadPipelineArtifact@2
      inputs:
        buildType: 'specific'
        project: '你的项目ID'
        definition: '构建流水线ID'
        buildVersionToDownload: 'latest'
        artifactName: 'myapp'
        targetPath: '$(Build.ArtifactsDirectory)'
    
  • 检查发布流水线的权限
    确认执行发布流水线的服务主体(或触发用户)拥有访问构建流水线构件的权限:进入构建流水线的「权限」设置,为发布流水线对应的服务账号添加「读取」构件的权限。

注:Build.ArtifactsDirectory是Azure DevOps默认的构件下载目录,无需替换,问题核心在于构件的定位逻辑而非下载路径。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 07:50:49