Azure DevOps流水线无法下载前序构建的Artifact,求故障排查
问题排查:Azure DevOps Pipeline跨运行实例持久化数据时Artifact下载失败
问题场景
想要在Pipeline的不同运行实例之间持久化数据,流程如下:
- 下载已存在的数字文本文件数据
- 运行脚本,使用该数据(若存在)生成新数据
- 发布新生成的数据
脚本运行及文件发布均正常,Pipeline报告中能看到已发布对应Artifact,但下载步骤始终失败,错误信息:
##[error]Artifact CheckWebsiteState was not found for build 10470.
Finishing: Download artifact
用户使用的YAML脚本:
name: $(Date:yyyyMMdd)$(Rev:-r) trigger: none pool: vmImage: 'ubuntu-latest' stages: - stage: CheckWebsite jobs: - job: Run steps: - download: current artifact: CheckWebsiteState displayName: 'Download artifact' continueOnError: true - task: AWSShellScript@1 displayName: CheckWebsite inputs: filePath: '$(System.DefaultWorkingDirectory)/scripts/check-website.sh' arguments: '$(Pipeline.Workspace)' - publish: $(Pipeline.Workspace) artifact: CheckWebsiteState displayName: 'Publish artifact'
原因分析
问题出在download: current的配置上:
current指向的是当前正在运行的Pipeline实例的Artifact,但当前实例在执行下载步骤时还未发布任何Artifact;即便是后续运行的实例,current依然指向自身,而不是之前成功运行的实例,自然找不到历史持久化的Artifact。
解决方案
要跨Pipeline运行实例共享数据,需要下载上一次成功运行实例的Artifact,修改下载步骤的配置如下:
- download: pipeline artifact: CheckWebsiteState displayName: 'Download latest successful artifact' continueOnError: true inputs: pipeline: $(System.DefinitionId) # 指定当前管道ID latest: true # 获取该管道最新成功的运行实例
补充说明
- 第一次运行Pipeline时,由于没有历史Artifact,下载步骤会失败,但
continueOnError: true会让流程继续执行,脚本需要处理“无历史数据”的场景来生成初始数据。 - 确认发布路径
$(Pipeline.Workspace)正确,确保新生成的数据能被正常发布,后续运行就能获取到上一次的持久化结果。
内容的提问来源于stack exchange,提问作者laurent
相关产品推荐
相关产品推荐

