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

查询Azure build pipelines在Microsoft托管代理上的构建日志完整存储路径

Microsoft 托管代理构建日志存储路径及保存到仓库方案

日志存储路径

Microsoft 托管代理运行时,当前作业的所有构建日志默认存放在 $(Agent.BuildDirectory)/Logs 目录下:

  • 全量整作业日志文件路径:$(Agent.BuildDirectory)/Logs/job.log
  • 各步骤拆分的日志文件:按步骤ID命名存放在同级目录,格式一般为[步骤ID].log

实现日志拷贝到仓库的操作

你无需调用构建日志相关的REST API,直接在流水线末尾追加文件拷贝、提交推送步骤即可:

YAML 流水线示例

# 1. 拷贝日志到仓库指定路径
- task: CopyFiles@2
  inputs:
    SourceFolder: '$(Agent.BuildDirectory)/Logs'
    Contents: '**/*.log'
    TargetFolder: '$(Build.Repository.LocalPath)/build-logs' # 替换为你仓库下的实际路径
    OverWrite: true

# 2. 提交日志到仓库
- script: |
    cd $(Build.Repository.LocalPath)
    git config --global user.name "Azure DevOps Build Agent"
    git config --global user.email "devops@your-domain.com"
    git add ./build-logs/*
    git commit -m "ci: add build logs for build ID $(Build.BuildId)"
    git push origin $(Build.SourceBranchName)
  displayName: Commit build logs to repo

经典界面流水线配置

  1. 新增「复制文件」任务,源文件夹填写 $(Agent.BuildDirectory)/Logs,目标文件夹填写仓库对应的相对路径
  2. 新增「命令行」任务,填写上述提交推送的脚本即可

注意事项

  • 上述用到的$(Agent.BuildDirectory)、$(Build.Repository.LocalPath)都是Azure DevOps内置预定义变量,自动适配Windows/Linux/macOS类型的托管代理,无需手动调整路径分隔符
  • 提交前请确认流水线的服务账号拥有对应仓库的贡献权限,避免推送失败

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 03:18:02